目录

力扣178. 分数排名

力扣178. Rank Scores(分数排名)

编写 SQL 查询,对 Scores 表中的分数进行排名。排名按分数从高到低排列,相同分数并列排名,排名连续不间隔。

表结构:

Scores

Column Name Type
id int
score decimal

id 是主键。

示例 1:

../posts/01_学习/87_LeetCode/0178_分数排名/img/0178-1-description.png

输入:
Scores 表:
| id | score |
|----|-------|
| 1  | 3.50  |
| 2  | 3.65  |
| 3  | 4.00  |
| 4  | 3.85  |
| 5  | 4.00  |
| 6  | 3.65  |

输出:
| score | rank |
|-------|------|
| 4.00  | 1    |
| 4.00  | 1    |
| 3.85  | 2    |
| 3.65  | 3    |
| 3.65  | 3    |
| 3.50  | 4    |