I'm trying to solve problem 13 from here: http://sqlzoo.net/wiki/The_JOIN_operation In it I'm supposed to "List every match with the goals scored by each team as shown". I thought this would be the answer:
SELECT
mdate, team1,
SUM(CASE WHEN teamid = team1 THEN 1 ELSE 0 END) score1,
team2,
SUM(CASE WHEN teamid=team2 THEN 1 ELSE 0 END) score2
FROM
game
JOIN
goal ON matchid = id
GROUP BY
team1, team2, mdate
ORDER BY
mdate
However, this query returns no rows if both teams score is 0. I tried wrapping the SUM in the ISNULL and COALESCE, but it doesn't help.
To tell you the truth I'm not really looking for an answer on how to solve the problem, but rather an answer explaining why is this query not showing me the rows when the score is 0:0. Also if someone could help me find the meaning behind 0 column_name or 1 column_name (as it seems to be the result of above CASE), it seems to be 0*column_name or 1*column_name, but I'm not certain, and google is filled with unrelated results when I try to search it for answers.
PS: Yes, I did read the first 20 suggested stack overflow questions with the same or similar names, I'm sorry if it's a duplicate