获取MySQL Query的位置

时间:2014-11-12 11:57:46

标签: mysql position

MySQL查询,列出按点和排名排序的所有记录。但是现在,如何从名称中获取特殊列?

查询:

    SET @a=0; 
    SELECT (@a:=@a+1) as Rank, `player`, `points`, `id` FROM `score` 
    ORDER BY `points` DESC (WHERE player='example');

感谢您的帮助。 :)

我正在使用Java。

2 个答案:

答案 0 :(得分:0)

select * from 
(
  SELECT (@a:=@a+1) as Rank, `player`, `points`, `id` 
  FROM `score` 
  CROSS JOIN (select @a := 0) ta
  ORDER BY `points` DESC
) tmp
WHERE player='example'

答案 1 :(得分:0)

在此WHERE之前使用ORDER BY子句 -

SET @a=0; 
SELECT (@a:=@a+1) as Rank, `player`, `points`, `id` FROM `score` 
WHERE player='example' ORDER BY `points` DESC;