1、获取所有学生成绩排名-并列排名
SELECT *,
(SELECT count(DISTINCT score) FROM table_score AS b WHERE a.score<b.score)+1 AS rank #获取排名-并列
FROM table_score AS a ORDER BY rank; #获取学生成绩排名
2、获取所有学生成绩排名-超过你的人数个数
SELECT *,
(SELECT count(score) FROM table_score AS b WHERE a.score<b.score)+1 AS rank #获取排名-并列
FROM table_score AS a ORDER BY rank; #获取学生成绩排名
3、获取所有学生成绩排名,不是并列排名。计算行号进行排名
SELECT a.*,
(@rowNum:=@rowNum+1) AS rank #计算行号
FROM table_score AS a,
(SELECT (@rowNum :=0) ) b
ORDER BY a.score DESC;
网友评论