My Current MySQL query:
SELECT MAX( s.con_grade ) AS max, YEAR( u.sent_date ) AS year
FROM pdb_usersectionmap u
LEFT JOIN pdb_sections s ON u.section_id = s.id
WHERE u.user_id =21
AND YEAR( u.sent_date ) > '2004-01-01'
GROUP BY YEAR( u.sent_date )
ORDER BY u.sent_date ASC
(The year and user_id are generated dynamically in PHP)
I'm trying to display results for the last 5 years. In some circumstances, the user may not have a MAX for that year. For instance, this user only has entries in the last 3 years (but no years before that):
max year
5 2007
6.05 2008
7 2009
My Question: If I tell MySQL to look for entries in specific years, is there any way for MySQL to return "0" for the year if there are no entries found?
Ideally, I'd love for the output to be (would save me a lot of time):
year max
2005 0
2006 0
2007 5
2008 6.05
2009 7