Row for each hour even if there is no record
- by peku33
I've got a trouble with creating mysql Query.
My PHP script executes this query on each run:
INSERT INTO Executes SET UserIp='%s' (%s is user IP)
Executes table is:
ExecuteId UNSIGNED BIGINT AI PRIMARY
Date TIMESTAMP DEFAULT CURRENT_TIMESTAMP INDEX
UserIp CHAR(24) ... | Some Columns
I want to retrive number of Executes in each hour. The most obvious solution would be:
SELECT COUNT(*) as ExecutesNum, DATE(Date) as D, HOUR(Date) as H GROUP BY D, H
And it works, BUT it does not create rows for hours where there were no executes.
What should I modify to get result like:
1 | 2012-09-01 | 14
**0 | 2012-09-01 | 15**
11 | 2012-09-01 | 16
1 | 2012-09-01 | 17