Actual Practise : Row_Number() over(partition by colnum1 order by colnum2 ) as No - 7
来源:互联网 发布:js数组的排序函数 编辑:程序博客网 时间:2024/06/03 19:03
Let us see a requirement :
we need show the Max(ID) of each loan record however each loan has one more records.
How will we do?
The best and the first way is :
Let me show you by Row_Number() Over(partition by colnum1 order by colnum2) as No to make it effective.
;with cte as(select Row_number() over (partition by servicerloannumber order by hmpmodificationdataid desc) as no, * from hmpmodificationdata where servicerloannumber in( '0015691793','0017522277','0015328560'))select * from cte where no = 1
See the results:
Let me explain:
1. partition by servicerloannumber : “servicerloannumber” is the colnum we make a group to the result;
2. order by hmpmodificationdataid desc : “hmpmodificationdataid” is the colnum we make the order to the result which has been grouped.
3. As No : we will add a number following the each record of loans. For example : If the loan has 3 records, then we will see **1,2,3**in front of the records by order which are used to identify the sum records and somewhere may be useful.
As the photograph :
Of course, if you wanna get more about it you can search it in Google or Baidu~~~
We can have some other ways to replace it but it is not the best way. However I still show you how to make it.
select * from hmpmodificationdata Awhere not exists ( select null from hmpmodificationdata B where 1=1 and a.servicerloannumber = b.servicerloannumber and a.hmpmodificationdataid < b.hmpmodificationdataid) and servicerloannumber in( '0015691793','0017522277','0015328560')
See the result:
Is it the same with upside?! Yes it is. I will use Chinese to explain :
- 在exists 中,select * 与select null效果一样;
- 在查询A表数据时,当servicerloannumber 相同时且存在hmpmodificationdataid更大(更新)时,则不要这条数据,一直排除到hmpmodificationdataid是最大的。
We all need to understand what it means.
- Actual Practise : Row_Number() over(partition by colnum1 order by colnum2 ) as No - 7
- Row_Number()over(order by....) as
- ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...)
- row_number() over (partition by....order by...)用法
- row_number() over (partition by....order by...)用法
- row_number() over (partition by....order by...)用法
- row_number() over(partition by 列名1 order by 列名2 desc1) as rank
- row_number() over(PARTITION BY
- row_number() over(partition by ... )
- row_number() over(partition by
- row_number() over(partition by a order by b desc) rn
- oracle中row_number() OVER (PARTITION BY COL1 ORDER BY COL2)
- row_number() OVER (PARTITION BY COL1 ORDER BY COL2)
- row_number() over(partition by column1 order by column2)
- row_number() OVER (PARTITION BY COL1 ORDER BY COL2)
- row_number() over (partition by....order by...)用法 二
- row_number() over (partition by....order by...)用法 一
- row_number() over(partition by xxx order by xxx)的用法
- oradebug
- Kubernetes技术分析之网络
- [CS]C#操作word
- SpringMVC异常处理综述
- nginx、fastCGI、php-fpm关系梳理
- Actual Practise : Row_Number() over(partition by colnum1 order by colnum2 ) as No - 7
- Facebook申请应用
- Hibernate注解方式多种映射
- 日志库选择
- 【笔试/面试】—— 二叉树的最远距离
- QNX下根据进程名查找PID
- 给超链接加onclick事件
- Does OS X not support epoll function?
- android5.1添加Email分享,bluetooth分享