有这样的一个表:
如果两个分数相同,则两个分数排名(Rank)相同平分后的下一个名次应该是下一个连续的整数值。
因此,名次之间不应该有“间隔”!
此时有2种方法:
第一:
select grade, (select count(distinct grade) from class3 where grade>=s.grade) as Rank from class3 as s order by grade desc;
第二:
select grade,(select count(*) from (select distinct grade as s from class3) as new_scores where s >= grade) Rank from class3 order by grade desc;