---
title: "mysql根据分数排名次sql语句"
author: "sky_xin"
date: "2017-06-07T19:32:25Z"
tags: ["SQL", "排名"]
categories: ["数据库"]
slug: "mysql-sql"
draft: false
lastmod: "2017-06-07T19:32:25Z"
id: 2378403
url: "https://sky-xin.iteye.com/blog/2378403"
---

```
更多可以参考：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
```