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;
新闻热点
疑难解答