I'm trying to extract data according to Day of Week & also Hour of day in the same statement (so I can see how many visits I got per hour and over a week. Here's the statement.
SELECT
count(id) as count,
HOUR(created) as hour_of_day,
WEEKDAY(created) as day_of_week,
DATE_FORMAT(created,'%W') name_of_day
FROM visitors
GROUP BY day_of_week,hour_of_day
ORDER BY day_of_week,hour_of_day ASC
Some sample data
count hour_of_day day_of_week name_of_day
2 0 0 Monday
1 1 0 Monday
1 4 0 Monday
4 5 0 Monday
1 6 0 Monday
4 7 0 Monday
1 9 0 Monday
1 10 0 Monday
1 12 0 Monday
1 13 0 Monday
2 16 0 Monday
5 18 0 Monday
5 19 0 Monday
The problem As you can see, there data missing for many hours in the data. And as I'm creating a graph which needs data in the form of [x,x,x,x,x,x,x] for each day which will be matched with a 24hr timeline starting from the first output, I need the missing ones to be '0'.
While I can handle it on the PHP end with loops, looping it for each day of the week & within that, for every hour, is rather tiresome and definitely not clean.
Is it possible without temporarily tables (like including the 24 digits in the query itself,etc?)?