As said in the title, I want to select the number of events per team and per year. The select statement below works fine but doesn't give me exactly what I am looking for.
SELECT
Team.team_id,
TO_CHAR(Event.START_DATE_TIME, 'yyyy') AS year,
count(event_id) AS events
FROM
Team
LEFT OUTER JOIN
Event ON Event.team_id = Team.team_id
GROUP BY
TO_CHAR(Event.START_DATE_TIME, 'yyyy'),
team_id
ORDER BY
year ASC,
team_id ASC
;
With this, if we have :
Team 1 : 1 event in 2006
Team 2 : 1 event in 2007
We obtain :
ID | Year | Events
------------------
1 | 2006 | 1
2 | 2007 | 1
And I would like to obtain :
ID | Year | Events
-------------------
1 | 2006 | 1
2 | 2006 | 0
1 | 2007 | 0
2 | 2007 | 1
I don't know how to modify my request to do so.