Is there a way to get all dates from the past week with mysql, even when they don't contain any records?
Now I have a query that looks something like this (for an app that can monitor working times etc):
SELECT user_id, SUM( TIME_TO_SEC( checkout_time ) - TIME_TO_SEC( checkin_time ) ) AS total_time, DATE( checkout_time ) AS checkout_day
FROM timetable
WHERE task_id = 19
AND checkout_time >= ( DATE_SUB( CURDATE( ) , INTERVAL 1 WEEK ) )
GROUP BY checkout_day, user_id
ORDER BY checkout_day ASC
This works really well, but I "only" get the dates a user actually have been clocked in (which is really the days that matters). But what would be really great if there where a way to get all the dates in that one week interval. If something like:
DATE(INTERVAL 1 WEEK) as dates
would retrieve:
|dates
------------
|2012-07-15
|2012-07-16
|2012-07-17
|2012-07-18
|2012-07-19
|2012-07-20
Might not be what you usually use SQL for, but if someone knows a way – you would make my day.