I'm using SQL Server and I have the following table:
tbl_Message:
id, date, group_id
Which is a table containing messages: it's id, the date it was sent, the group it was sent in. I'm trying to calculate the number of messages received every day. I made a query for it but it doesn't return days with no messages. The query is:
SELECT DATEADD(MINUTE, DATEDIFF(MINUTE, 0, date)/1440 * 1440,0) AS dateDay,
COUNT(*) AS countMsgDay
FROM tbl_Message
WHERE group_id = 1
GROUP BY DATEADD(MINUTE, DATEDIFF(MINUTE, 0, date)/1440 * 1440,0)
Example:
For tbl_Message
id | date | group_id
----------------------------------------
1 | 2014-10-01 21:04:00.000 | 1
2 | 2014-10-03 21:09:00.000 | 1
The query returns:
dateDay | countMsgDay
---------------------------------
2014-10-01 00:00:00.000 | 1
2014-10-03 00:00:00.000 | 1
and what I want is:
dateDay | countMsgDay
---------------------------------
2014-10-01 00:00:00.000 | 1
2014-10-02 00:00:00.000 | 0
2014-10-03 00:00:00.000 | 1