分数排名
用sql实现分数排名。如果两个分数相同则相同排名,下个为排名连续值,无间隔。
一、用子查询
select a.Score ,(select count(distinct b.Score )as rank from Scores b where b.Score >= a.Score) as ranks from Scores a order by ranks asc ;
2.用窗口函数 row_number()over(order by Score )
一、用子查询
select a.Score ,(select count(distinct b.Score )as rank from Scores b where b.Score >= a.Score) as ranks from Scores a order by ranks asc ;
2.用窗口函数 row_number()over(order by Score )