ID username score
4 | x | 7
7 | y | 3
9 | z | 6
我想从MySQL学习y在记分牌(即3)的位置。我找不到真正的MySQL查询,你能帮帮我吗?
答案 0 :(得分:2)
SELECT * FROM
(SELECT @rank := @rank + 1 AS rank, id,username, score
FROM table , (SELECT @rank := 0) r
ORDER BY score
) k
WHERE k.username = 'y'