https://leetcode-cn.com/problems/rank-scores/
Rank比较难想出来,这里的思路是对于任意分数X,X的排名Rank等价于其他分数中大于等于X分数的(去重)个数,例如X=100分,属于最高分,那么大于等于X的分数个数就为1,也就是排名为1。
select s1.Score, count(distinct s2.Score) Rank
from scores s1, scores s2
where s1.Score<=s2.Score
group by s1.id
order by s1.Score desc;