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


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

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


[img]http://dl.iteye.com/upload/attachment/0075/2112/c4003ca3-f2ce-3f53-9be2-e92fbb388492.png[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值