ITeye博客

mysql根据分数排名次sql语句

sky_xin · 2017-06-07 19:32 · oracle · mysql · 数据库 · SQL · 排名 · Markdown

更多可以参考:http://blog.csdn.net/fn_2015/article/details/54286366
下面是我自己写的sql
相同分数的名次相同的情况 :
SELECT
	t.*,
	(
		SELECT
			count(*) + 1
		FROM
			(
				SELECT
					t1.score
				FROM
					t_student_score t1
				WHERE
					1 = 1
				GROUP BY
					t1.score
			) t2
		WHERE
			t2.score > t.score

	) AS rank
FROM
	t_student_score t
WHERE
	1 = 1
ORDER BY
	t.score desc
LIMIT 20

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。