我有一张桌子(GamesSchedule),其中包括锦标赛名称,裁判名称,日期,然后是一个包含所有锦标赛列表的视图。我需要的是在特定日期范围内每个锦标赛中特定裁判的比赛数量 - 而且我确实需要空位以查看裁判没有参加的锦标赛(并且,不,我没有找到了一个能够帮助我正确的答案):
Tourney | Games
----------------
Mens 1st | 10
Womens 1st | 7
Cup | 0
Youth | 3
Mens 2nd | 2
Womens 2nd | 0
----------------
不幸的是,这只给了我裁判上过比赛的比赛(所以六场比赛只有四场,上面没有杯赛):
SELECT t.Tourney, COUNT(t.Tourney) AS Games
FROM GamesSchedule t
RIGHT JOIN Tournaments v
ON t.Tourney = v.Tourney
WHERE Date > 42603 AND Date < 43011
AND (D1='Joe Smith' OR D2='Joe Smith' OR D3='Joe Smith')
GROUP BY t.Tourney;
答案 0 :(得分:0)
尝试将条件从WHERE
移至JOIN
:
SELECT t.Tourney, COUNT(t.Tourney) AS Games
FROM GamesSchedule t
RIGHT JOIN Tournaments v
ON t.Tourney = v.Tourney
AND Date > 42603
AND Date < 43011
AND 'Joe Smith' IN (D1, D2, D3)
GROUP BY t.Tourney;