- 并列跳躍排名
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;