mysql分数排名,分数相同名次相同
比如给定一张scores
| id | score |
|---|---|
| 1 | 33.2 |
| 2 | 35.4 |
| 3 | 35.4 |
| 4 | 36.4 |
| 5 | 37.3 |
| 6 | 37.3 |
| 7 | 38.4 |
要求排序后输出
| 名次 | score |
|---|---|
| 1 | 38.4 |
| 2 | 37.3 |
| 2 | 37.3 |
| 3 | 36.4 |
| 4 | 35.4 |
| 4 | 35.4 |
| 5 | 33.2 |
select s.score ,
(select count(distinct m.score)+1 from scores m where m.score> s.score)
from scores s order by s.score desc