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;

  

上一篇:python3 入门 (四) 类与继承


下一篇:vue:element-ui输入框绑定回车事件