从记分牌中查找球员的等级

时间:2012-08-10 08:32:38

标签: mysql

ID username score

4 |  x     | 7
7 |  y     | 3
9 |  z     | 6

我想从MySQL学习y在记分牌(​​即3)的位置。我找不到真正的MySQL查询,你能帮帮我吗?

1 个答案:

答案 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'