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;