I have a table, let's call it "log" and in this table there is a date column in datetime format (yyy-mm-dd hh:mm:ss) and a text column called log (for example's sake). I need to do a report which shows all of the log entries between START_DATE and END_DATE. Easy enough. The problem is that I want the results to be grouped by DAY in this report, such that it would look something like:
DAY | TOTAL
2007-01-01 | 10
2007-01-02 | 8
2007-01-03 | 0
2007-01-04 | 5
The tricky part here is that if there were no entries made on 2007-01-03, then there would be no row with that date in it. As such, instead of the above example, I get back 3 rows (with no row where the 2007-01-03 should be).
Is there any way at all I can make mysql return a row for each date between START and END with empty data to go with the dates for which there is no data?
I know this could be worked out programmatically outside of the query, but because of reasons not worth getting into (automatic sorting and report generation), I need to get this all into the query result. Doesn't mysql have some magic way of generating it's own list of dates somehow to step through and fill in the blanks?
Thanks