1
SELECT COUNT(m.winner = p.userName) AS wins, YEAR(m.datePlayed) AS year, DATE_FORMAT(m.datePlayed, '%M') AS month, COUNT(*) as games FROM allMatches AS m LEFT JOIN playerUsers AS p ON m.season = p.season AND (m.player1 = p.userName OR m.player2 = p.userName) WHERE p.realName = '$realName' AND m.winner != '' AND m.canceled != '1' GROUP BY YEAR(m.datePlayed), MONTH(m.datePlayed)";
我們有2個表我們加入:allMatches和playerUsers。 PlayerUser有一個用戶名,該用戶名與給定季節的allMatches表中的player1或player2(可能是贏家)相匹配。計數行數和數值匹配
我想統計玩過的遊戲數量(他們所在的任何比賽)以及他們贏得的比賽數量(其中他們的用戶名在playerUsers上與所有匹配的獲勝者相匹配)。上面的SQL語句返回勝利和遊戲作爲相同的數字。有沒有辦法在同一個SQL語句中計算勝利和遊戲的數量?