关于dense_rank()与rank()的区别
dense_rank与rank()用法相当,但是有一个区别:dence_rank在处理相同的等级时,等级的数值不会跳过。rank则跳过。
?
? 例如:表
??? A B C
a????????? liu????????? wang
a????????? jin????????? shu
a????????? cai????????? kai
b????????? yang????? du
b????????? lin????????? ying
b????????? yao??????? cai
b????????? yang????? 99
例如:当rank时为:
select m.a,m.b,m.c,rank() over(partition by a order by b) liu from test3 m
A????????? B???????????? C????????? LIU
a????????? cai????????? kai????????? 1
a????????? jin?????????? shu??????? 2
a????????? liu?????????? wang???? 3
b????????? lin?????????? ying??????? 1
b????????? yang????? du?????????? 2
b????????? yang????? 99?????????? 2
b????????? yao??????? cai?????????? 4
而如果用dense_rank时为:
select m.a,m.b,m.c,dense_rank() over(partition by a order by b) liu from test3 m
A????????? B???????????? C????????? LIU
a????????? cai????????? kai????????? 1
a????????? jin?????????? shu??????? 2
a????????? liu?????????? wang???? 3
b????????? lin?????????? ying??????? 1
b????????? yang????? du?????????? 2
b????????? yang????? 99?????????? 2
b????????? yao??????? cai?????????? 3