I am working with a climate database that has three tables. An event table which holds the datetime that a weather event took place, the type of event and the state the event took place in. The second table is a fatality event table which is linked through an ID number from the first table. Finally, there is a table which holds a list of years (1950, 1951, 1952 etc.).
I've written the following:-
SELECT
State,
YEAR(BeginDate) as Year,
COUNT(*) as CountOfEvents
FROM
[StormEvents].[dbo].[DT_Event]
JOIN
[StormEvents].[dbo].[DT_FatalityEvent] ON [StormEvents].[dbo].[DT_Event].EventID = [StormEvents].[dbo].[DT_FatalityEvent].EventID
WHERE
EventType like'%tornado%'
AND YEAR(BeginDate) >= 1995
AND YEAR(BeginDate) <= 2014
GROUP BY
State, YEAR(BeginDate)
ORDER BY
State, YEAR(BeginDate)
which summarises the number of fatality events per month per state. The query above works but it omits any counts which return a count of 0.
I've attempted adding this line after reading about joins:-
RIGHT JOIN
[StormEvents].[dbo].[DT_YearValues] ON YEAR([StormEvents].[dbo].[DT_Event].BeginDate) = [StormEvents].[dbo].[DT_YearValues].[Year]
but this isn't returning 0's in the fields where the count of fatality events for that state and year is 0.
Can anyone suggest where I am going wrong?
Thanks!