Closed. This question is off-topic。它当前不接受答案。
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
在11个月前关闭。
我正在为我的实习,我们在休息时间玩的比赛做一个计分板。我有一个非常大的查询要获取所有游戏的结果并计算玩家的总胜利数。
输出:
那不是正确的顺序。有什么不对?
因为您只是错过了
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
在11个月前关闭。
我正在为我的实习,我们在休息时间玩的比赛做一个计分板。我有一个非常大的查询要获取所有游戏的结果并计算玩家的总胜利数。
SELECT winner, SUM(total) AS total
FROM (SELECT pw.name AS `winner`, COUNT(*) AS total
FROM billiard_games g
INNER JOIN players p1
ON p1.id = g.player_1
INNER JOIN players p2
ON p2.id = g.player_2
LEFT JOIN billiard_winners w
ON w.id = g.id
LEFT JOIN players pw
ON pw.id = w.winner
WHERE winner IS NOT NULL
GROUP BY winner
UNION ALL
SELECT pw.name AS `winner`, COUNT(*) AS total
FROM dart_games g
INNER JOIN players p1
ON p1.id = g.player_1
INNER JOIN players p2
ON p2.id = g.player_2
LEFT JOIN dart_winners w
ON w.id = g.id
LEFT JOIN players pw
ON pw.id = w.winner
GROUP BY winner
UNION ALL
SELECT pw.name AS `winner`, COUNT(*) AS total
FROM fifa_games g
INNER JOIN players p1
ON p1.id = g.player_1
INNER JOIN players p2
ON p2.id = g.player_2
LEFT JOIN fifa_winners w
ON w.id = g.id
LEFT JOIN players pw
ON pw.id = w.winner
WHERE winner IS NOT NULL
GROUP BY winner ) A
WHERE winner IS NOT NULL
group by winner DESC
LIMIT 5
输出:
Player_1 | 5
Player_2 | 1
Player_3 | 3
那不是正确的顺序。有什么不对?
最佳答案
最后一部分应该是
WHERE winner IS NOT NULL group by winner order by total DESC LIMIT 5
因为您只是错过了
ORDER BY
关于php - 降序在查询中不起作用,但是应该起作用? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55101431/
10-15 22:03