- 并列跳跃排名
select
score,
(
select count(score) + 1 from score s2
where s2.score > s.score
) ranking
from score s order by score desc;
- 并列连续排名
select
score,
(
select count(distinct score) from score s2
where s2.score >= s.score
) ranking
from score s order by score desc;
- 分组并列跳跃
select
score,
course_id,
(
select count(score) + 1 from score s2
where s2.course_id = s.course_id and s2.score > s.score
) ranking
from score s
order by course_id,score desc;
- 分组并列连续
select
score,
course_id,
(
select count(distinct score) from score s2
where s2.course_id = s.course_id and s2.score >= s.score
) ranking
from score s
order by course_id,score desc;