以下语句是得出一个排名的字段,但是只有CNT值相同则下一个名次就不对了,如截图,请问如何解决?
select *,(select count(1)+1 from loginCnt a where a.cnt>b.cnt) as 名次
from loginCnt b order by cnt desc
------解决方案--------------------
- SQL code
select * ,rn=dense_rank()over(order by cnt desc)from loginCnt
------解决方案--------------------
- SQL code
SQL2000这样用-- count(DISTINCT a.cnt)select *,(select count(DISTINCT a.cnt)+1 from loginCnt a where a.cnt>b.cnt) as 名次from loginCnt b order by cnt desc