Row for each hour even if there is no record
Posted
by
peku33
on Stack Overflow
See other posts from Stack Overflow
or by peku33
Published on 2012-09-09T15:30:55Z
Indexed on
2012/09/09
15:38 UTC
Read the original article
Hit count: 123
mysql
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
© Stack Overflow or respective owner