Mysql查询指定用户并列排名 类似rank函数

SELECT
	total.*
FROM
	(
		SELECT
			obj.uid,
			obj.score,
			CASE
		WHEN @rowtotal = obj.score THEN
			@rownum
		WHEN @rowtotal := obj.score THEN
			@rownum :=@rownum + 1
		WHEN @rowtotal = 0 THEN
			@rownum :=@rownum + 1
		END AS rownum
		FROM
			(
				SELECT
					uid,
					score
				FROM
					t
				ORDER BY
					score DESC
			) AS obj,
			(
				SELECT
					@rownum := 0 ,@rowtotal := NULL
			) r
	) AS total
WHERE
	total.uid = 222;

  

上一篇:【单点登录】【两种单点登录类型:SSO/CAS、相同一级域名的SSO】


下一篇:SQL 命令未正确结束