我想创建一个查询,以获得玩家获胜的所有匹配。
所以,我有这张表
ID_PLAYER1 ID_PLAYER2 SCORE_PLAYER1 SCORE_PLAYER2
1 4 5 3
2 1 3 4
3 4 2 0
我想要这个:
ID_PLAYER MATCH_WIN
1 2
2 0
3 1
4 0
谢谢!
答案 0 :(得分:0)
我正在回答这个问题,因为这是非常重要的,因为我想知道我是否真的可以这样做:p
SELECT `ID_PLAYER`, COUNT(*) AS `MATCH_WIN` FROM
(SELECT
IF(`SCORE_PLAYER1`>`SCORE_PLAYER2`, `ID_PLAYER1`, `ID_PLAYER2`) AS `ID_PLAYER`
FROM `your_table_name_here`
) AS `tmp`
GROUP BY `ID_PLAYER`