1.排名rank/dense_rank
示例:
对于上述问题,可以使用dense_rank聚集函数解决:
select Score dense_rank() over( order by (Score) desc) as Rank
from Scores
order by s_rank
而如果是要平局之后的下一个名次是非连续的,则应该用rank(),用法与dense_rank一样。
如果不用rank函数,也可以实现上述问题:
select Score ,(1+(select count(distinct score)
from Scores as B
where B.score>A.score)) as Rank
from Scores as A
order by Rank
而如果要非连续的,则把上边的关键字distinct去掉即可。