Solution#1
# Write your MySQL query statement below
SELECT
Score,
(SELECT COUNT(DISTINCT Score) FROM Scores WHERE S.Score <= Score) Rank
From Scores S
ORDER BY Score DESC
Solution#2
# Write your MySQL query statement below
SELECT s.Score, count(distinct t.Score) Rank
From Scores s JOIN Scores t ON s.Score <= t.Score
GROUP BY s.Id
ORDER BY s.Score DESC
第一種方法更快
第二種方法中,必須加上GROUP BY,否則count後的結果中會有null和0;