lostcommander
Member
- Messages
- 52
- Reaction score
- 0
- Points
- 6
I have a table with a timestamp column. I would like to get the count of the number of rows in the table corresponding to each of the past 7 days. My problem is that I get no row if there are none, instead of {[date], 0}. Can anyone provide me with a clever solution to this?
Current MYSQL query:
Example current return:
2009-10-25, 2
2009-10-24, 11
2009-10-22, 6
What I want returned:
2009-10-25, 2
2009-10-24, 11
2009-10-23, 0
2009-10-22, 6
After I have the existing query, I can use PHP to add in the empty rows, but that seems a bit wasteful and inelegant.
Current MYSQL query:
Code:
SELECT DATE(submit_dt) AS date, COUNT(id)
FROM db_itemtable
WHERE DATE(submit_dt) > DATE(TIMESTAMPADD(DAY,-4,NOW()))
GROUP BY date;
2009-10-25, 2
2009-10-24, 11
2009-10-22, 6
What I want returned:
2009-10-25, 2
2009-10-24, 11
2009-10-23, 0
2009-10-22, 6
After I have the existing query, I can use PHP to add in the empty rows, but that seems a bit wasteful and inelegant.