方法一.首先要通过题目降序,id升序,那么sql应该为:
select a.id,a.number from passing_number a order by a.number desc, a.id asc;要得到通过题目的排名,比如你通过了8分,,你同学a也通过了8分,找到大于等于你的成绩,一个9分,一个8分,一个8分,去重复,就一个9,一个8,count一下总数,第2名,如果有三个同学通过了7个呢,同理,9,8,8,7,7,7 后面比这个少的,已经死在了筛选条件,去重,9,8,7,count=3,所以sql为:
select count(distinct b.number) from passing_number b where b.number>=X联立为:
select a.id,a.number, (select count(distinct b.number) from passing_number b where b.number>=a.number ) from passing_number a order by a.number desc, a.id asc;
SELECT *, dense_rank ( ) over ( ORDER BY number DESC ) `rank` FROM passing_number ORDER BY `rank`, id