到目前为止,我已经在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"
答案 0 :(得分: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'
答案 1 :(得分: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 演示。