错误:
select score,
dense_rank() over (order by score desc) as rank
from scores
order by score desc;
正确:
select score,
dense_rank() over (order by score desc) as 'rank'
from scores
order by score desc;
报错形式:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'rank from scores order by score desc' at line 3
来源:
表: Scores
+-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | score | decimal | +-------------+---------+ 在 SQL 中,id 是该表的主键。 该表的每一行都包含了一场比赛的分数。Score 是一个有两位小数点的浮点值。
查询并对分数进行排序。排名按以下规则计算:
- 分数应按从高到低排列。
- 如果两个分数相等,那么两个分数的排名应该相同。
- 在排名相同的分数后,排名数应该是下一个连续的整数。换句话说,排名之间不应该有空缺的数字。
按 score
降序返回结果表。