`

oracle聚合函数-----rank()和dense_rank()分类排名

阅读更多
DENSE_RANK(n1[,n2]...) WITHIN GROUP (ORDER BY col1 [desc|asc] [nulls first|last] [,col2 [desc|asc] [nulls first|last]]...) 计算指定值在记录集中的排序值。函数的参值必须一一对应group中的列,并且二者数据类型应该一致。至于order by子句中的nulls first|last则是用来设置记录集中值为null的列的排序在前或在后。
RANK() 参数及形式完全与上同,二区最大的区别是:RANK函数在处理指定数值在记录集中的排序值时,如果值有重复,则后面的排序值会跳过这个值,直接从当前排序值+重复记录数开始,而DENSE_RANK则不会,排序值依然是个连续的序列。

select scott.emp.ename,scott.emp.deptno, scott.emp.sal,rank()over(partition by scott.emp.deptno order by scott.emp.sal) from scott.emp




select scott.emp.ename,scott.emp.deptno, scott.emp.sal,dense_rank()over(partition by scott.emp.deptno order by scott.emp.sal) from scott.emp



  • 大小: 18.1 KB
  • 大小: 18.6 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics