I have a table with dated records. I want a query that will show the number of records for each date.
Not hard, just a GROUP BY, right? Sure.
But I want to also show days where there were NO records. In this case, I would need to left join against a one-column table of consecutive dates, since a GROUP BY isn’t going to show a date that doesn’t exist.
Is there a better way of doing this? Or do I have to create a populate a table of dates just so I can join against it?
It would probably be easiest to build out the dates table
For example, if you wanted all dates from Jan 1, 2009 to today you could do the following:
@dates will have a record for each day from @start to @end.