mysql根据成绩排名次

  • (1,2,2,4 , 5)
select t.score,(select count(s.score)+1 from score s where s.score>t.score) rank from score t order by t.score desc;
  • (1,2,2,3 , 3)
select t.score,(select count(s.score)+1 from (select s.score,count(s.score) from score s group by score order by score desc) s where s.score>t.score) rank from score t order by t.score desc;

你可能感兴趣的:(PHP+MYSQL)