I have a table which logs hits on urls
The goal is to get all hits
for parent
grouped by days
parent
representing the id of the url
time
being an int generated by PHP's time()
id | parent | time
The query I came up with so far: (assuming I would want to select item 2929
)
SELECT time, count( * ) AS hits
FROM `hits`
WHERE parent =2929
GROUP BY floor( time /86400 )
ORDER BY time ASC
The problem now is, that I only get 5 rows
time hits
1355761244 9
1355791721 22
1355879697 23
1355966014 16
1356070906 24
Since MySQL won't return days with 0 hits.
How can I fix this?
Goal would be to e.g. select the last 7 or 30 or 365 days and receiving days with 0
hits aswell
Updated Query to select days of the last month:
SELECT floor(time/86400) AS day, count( * ) AS hits
FROM `hits`
WHERE parent =2929
AND time > ONE_MONTH_AGO
GROUP BY day
ORDER BY time ASC
LIMIT 0 , 30
With Pharaoh's PHP function this should work fine.