我有这个查询:
SET @playerRank = 0;
SELECT *, @playerRank := @playerRank + 1 AS Rank FROM
( SELECT
P.name AS nome,
(playerMMR_RT(P.pid) - DecayTimeDiffRT(P.pid)) AS MMR,
P.pid
FROM
players_rt P
) AS TableData
ORDER BY
MMR DESC,
nome ASC
请注意,playerMMR_RT
和DecayTimeDiffRT
返回两个整数值,但这并不重要。结果是这样的:
但是我想要这个输出:
基本上,结果很好,因为行按MMR
排序。我希望等级为1、2、3 ...,但似乎它也按行排序。
我该如何解决?我需要对表进行排序,并且排序表中的排名要升至1、2、3...。
答案 0 :(得分:1)
尝试在子查询内部移动订单
SET @playerRank = 0;
SELECT *, @playerRank := @playerRank + 1 AS Rank
FROM (
SELECT
P.name AS nome,
(playerMMR_RT(P.pid) - DecayTimeDiffRT(P.pid)) AS MMR,
P.pid
FROM players_rt P
ORDER BY MMR DESC, nome ASC
) AS TableData
ORDER BY rank
或者尝试在排序结果上应用排名
SET @playerRank = 0;
SELECT t.*, @playerRank := @playerRank + 1 AS Rank
from (
select *
FROM (
SELECT
P.name AS nome,
(playerMMR_RT(P.pid) - DecayTimeDiffRT(P.pid)) AS MMR,
P.pid
FROM players_rt P
) AS TableData
ORDER BY MMR DESC, nome ASC
) t
order by rank