MySQL average number of hours between created datetimes for a specific time interval
问题 I have a table with a field called "created" which is a datetime field. Assume NOW() is midnight on 2013-07-21, so NOW() = 2013-07-21 23:59:59 Now let's say I query for all records WHERE created BETWEEN DATE_SUB(NOW(), INTERVAL 4 DAYS) AND NOW() Let's say that returns results like this: 2013-07-18 08:00:00 2013-07-19 08:00:00 2013-07-20 08:00:00 2013-07-21 08:00:00 I want to add the start and end datetime for the interval I used (4 days) to that result set, so now I have: 2013-07-18 00:00:00