Solution#1
# Write your MySQL query statement belowSELECT Score, (SELECT COUNT(DISTINCT Score) FROM Scores WHERE S.Score <= Score) Rank From Scores S ORDER BY Score DESCSolution#2
# Write your MySQL query statement belowSELECT s.Score, count(distinct t.Score) RankFrom Scores s JOIN Scores t ON s.Score <= t.ScoreGROUP BY s.IdORDER BY s.Score DESC第一種方法更快 第二種方法中,必須加上GROUP BY,否則count后的結果中會有null和0;
新聞熱點
疑難解答