LeetCode.178. 分数排名

LeetCode.178. 分数排名_第1张图片
思路:

即无间隔排名。对于每个数字比较分数中有多少个大于等于自己的数,即为自身排名。

代码:

select Score,
(select count(distinct Score) from Scores as s2 where s2.Score >= s1.Score) as Rank 
from Scores as s1
order by Score DESC;

你可能感兴趣的:(Leetcode,SQL)