1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
-- @Title: 分数排名 (Rank Scores)
-- @Author: 15816537946@163.com
-- @Date: 2021-03-03 15:55:32
-- @Runtime: 677 ms
-- @Memory: 0 B
# Write your MySQL query statement below

select 
S1.score 'Score',
count(DISTINCT S2.score) 'Rank'
FROM
Scores S1 
INNER JOIN Scores S2 
ON S1.score <= S2.score
GROUP BY
S1.id, S1.score 
ORDER BY S1.score DESC;