我试图拉出一个团队的输赢记录,在这种情况下是团队 1。团队可以玩多种格式,记录对这些进行相应的分组。它工作得很好,除非一支球队没有以某种格式打平(可能也是为了获胜,但我在数据库中没有任何不赢的球队),然后它拒绝获取该格式的任何数据. 我需要它为绘图返回一个零,从而显示该格式的其余结果。查询如下:
SELECT matches.format, count(id) as played, a.wins, b.draws, count(id)-a.wins-b.draws as loss
FROM matches
INNER JOIN (SELECT format, count(id) as wins
FROM matches
WHERE winner=1
GROUP BY format) as a ON matches.format=a.format
INNER JOIN (SELECT format, count(id) as draws
FROM matches
WHERE hometeam=1
AND winner=-1
OR awayteam=1
AND winner=-1) as b ON matches.format=b.format
WHERE matches.hometeam=1
OR matches.awayteam=1
GROUP BY format
这返回
format played wins draws loss
1 14 9 1 4
但完全忽略了这支球队也打过6场“2”赛制,4胜2负,没有平局。任何帮助将非常感激