小丑鱼0703 发表于 2013-1-14 08:45:52

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

DENSE_RANK(n1[,n2]...) WITHIN GROUP (ORDER BY col1 [,col2 ]...) 计算指定值在记录集中的排序值。函数的参值必须一一对应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

http://dl.iteye.com/upload/attachment/0075/2102/57b99d0c-9c22-3502-9c49-ba616e327e18.png

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

http://dl.iteye.com/upload/attachment/0075/2112/c4003ca3-f2ce-3f53-9be2-e92fbb388492.png
页: [1]
查看完整版本: oracle聚合函数-----rank()和dense_rank()分类排名