1

到目前为止,我已经在 stackoverflow 上看到了针对此问题的解决方案,而且每个解决方案似乎都不同。所以我决定提出一个新问题。

我的目标是使用递增伤害创建一个排名列...

SET @rownum := 0;

SELECT rank, damage, playerID FROM (
                        SELECT @rownum := @rownum + 1 AS rank, damage, playerID
                        FROM PlayerStats WHERE playerID > 20130000000000 ORDER BY damage DESC, modified ASC
                    ) as result WHERE playerID='20130000000004' 

但是,它会报告“字段列表中的未知列“损坏””

"playerID","ancientBossID","damage","eventEnergy"

"20130000000004","2012000000000382","19033","38"
"20130000000078","2012000000000019","0","30"
"20130000000066","2012000000000242","0",30"
"20130000000080","2012000000000024","270","25"
"20130000000041","2012000000000133","5808","2"
"20130000000071","2012000000000030","694","30"
"20130000000055","2012000000000189","0","30"
4

2 回答 2

1
SELECT rank, damage, playerID,modified FROM (
                        SELECT ROW_NUMBER() over(ORDER BY damage DESC, modified ASC)  AS rank, damage, playerID,modified
                        FROM PlayerStats WHERE playerID > 20130000000000 
                    ) as result WHERE playerID='20130000000004' 
于 2013-06-26T05:38:47.527 回答
0

这是带有外观更改的查询,其中主要是@rownum子查询中的初始化

SELECT rank, damage, playerID 
FROM 
(
  SELECT @rownum := @rownum + 1 rank, damage, playerID
    FROM PlayerStats, (SELECT @rownum := 0) n
   WHERE playerID > 20130000000000 
   ORDER BY damage DESC, modified
) r 
-- WHERE playerID='20130000000004'
ORDER BY rank

它工作得很好。这是SQLFiddle演示。

于 2013-06-26T05:24:03.113 回答