1.排名rank/dense_rank
示例:
對(duì)于上述問題典予,可以使用dense_rank聚集函數(shù)解決:
select Score dense_rank() over( order by (Score) desc) as Rank
from Scores
order by s_rank
而如果是要平局之后的下一個(gè)名次是非連續(xù)的,則應(yīng)該用rank()乐严,用法與dense_rank一樣瘤袖。
如果不用rank函數(shù),也可以實(shí)現(xiàn)上述問題:
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
而如果要非連續(xù)的昂验,則把上邊的關(guān)鍵字distinct去掉即可捂敌。