So i have this table. It has some hundreds of rows. Every row has a datetime field in it. And what i need to acomplish is to get how much rows there are in given period of time but not for the whole period but for every day in this period. Till this point i know what to do. But moreover i need to have also rows for the days that does not have any row in the table with value 0.
So for example:
2012-01-01 12:13
2012-01-01 43:32
2012-01-03 23:32
Should give me the result like this:
2012-01-01 2
2012-01-02 0
2012-01-03 1
Anyone can help??
To deal with dates with 0 corresponding records, my normal practice is to use a calendar table to join on.
For example, create a table with one field called
calendar_dateand populate it with every date from1st Jan 2000to31st Dec 2070, or some other range that suits your reporting purposes.Then use something like…
This table can have many extra uses, such as flagging bank holidays, starts of weeks and months. With prudent uses of flags and indexes, you can get a lot out of it.