排序函数 rank() dense_rank()
排序函数:
1.rank() over(partition by 分组项 order by 排序项 [desc|asc])
2.dense_rank() over(partition by 分组项 order by 排序项 [desc|asc])
区别:
dence_rank在并列关系后,不会跳过等级。rank则跳过。
例子:
1.select sal,rank() over(partition by deptno order by sal desc) from emp;(跳过)
SAL RANK()OVER(PARTITIONBYDEPTNOORDERBYSALDESC)
---------- -------------------------------------------
5000 1
2450 2
1300 3
3000 1
3000 1
2975 3
1100 4
800 5
2850 1
1600 2
1500 3
SAL RANK()OVER(PARTITIONBYDEPTNOORDERBYSALDESC)
---------- -------------------------------------------
1250 4
1250 4
950 6
2.select deptno,sal,dense_rank() over(partition by deptno order by sal desc) (不跳过)
from emp;
DEPTNO SAL DENSE_RANK()OVER(PARTITIONBYDEPTNOORDERBYSALDESC)
---------- ---------- -------------------------------------------------
10 5000 1
10 2450 2
10 1300 3
20 3000 1
20 3000 1
20 2975 2
20 1100 3
20 800 4
30 2850 1
30 1600 2
30 1500 3
DEPTNO SAL DENSE_RANK()OVER(PARTITIONBYDEPTNOORDERBYSALDESC)
---------- ---------- -------------------------------------------------
30 1250 4
30 1250 4
30 950 5
3.合计排序功能:计算出数值(4,1)在Orade By Col1,Col2排序下的排序值,也就是col1=4,col2=1在排序以后的位置
SELECT RANK(4,1) WITHIN GROUP (ORDER BY col1,col2) "Rank" FROM table;
结果如下:
Rank
4
通过以上方法,得出col1为4,col2为1的那行数据的rank排名为多少
转载于:https://www.cnblogs.com/sisier/p/4661031.html
- 关于排序rank () over , row_number() over ,rank_dense ()函数使用
- SQLServer 2005 实现排序报表的利器 排序函数RANK()、DENSE_RANK()、NTILE()和ROW_NUMBER()
- Oracle分析函数-排序排列(rank、dense_rank、row_number、ntile)
- SQLServer 2005 实现排序报表的利器 排序函数RANK()、DENSE_RANK()、NTILE()和ROW_NUMBER()
- MS SQL 2005 四个排序函数ROW_NUMBER、RANK、DENSE_RANK 和 NTILE简介用法/结果排名排序
- SQL Server 2005四个新的排序函数: ROW_NUMBER、RANK、DENSE_RANK 和 NTILE
- MSSQL 排序函数 ROW_NUMBER() RANK() DENSE_RANK() NTILE()
- Oracle中row_number()、rank()、dense_rank() 三种排序函数的区别
- SQL Server 2005四个新的排序函数: ROW_NUMBER、RANK、DENSE_RANK 和 NTILE
- 数据库SQL中对查询结果排序排列序号编号,Oracle分析函数 rank,dense_rank,row_number使用和区别
- sqlserver 开窗函数over RANK(),DENSE_RANK(),ROW_NUMBER()三个排序的不同
- SQLServer2005增加的排序函数RANK(),DENSE_RANK(),ROW_NUMBER(),NTILE()
- SQL SERVER 排序函数ROW_NUMBER、RANK、DENSE_RANK、NTILE
- (转)SQL Server 2005四个新的排序函数: ROW_NUMBER、RANK、DENSE_RANK 和 NTILE
- 在SQL2005中利用DENSE_RANK()排名函数对现有数据进行排序改造
- Oracle-分析函数之排序值rank()和dense_rank()
- SQLServer 2005 实现排序报表的利器 排序函数RANK()、DENSE_RANK()、NTILE()和ROW_NUMBER()
- SQL Server 2005四个新的排序函数: ROW_NUMBER、RANK、DENSE_RANK 和 NTILE
- oracle笔记(5)----排序函数row_number、rank、dense_rank
- SQLServer 2005 实现排序报表的利器 排序函数RANK()、DENSE_RANK()、NTILE()和ROW_NUMBER()