I have a list of reservations in a MySQL db, and I want to determine total number of slots reserved in 15 minute intervals. To do that, I need to 'unroll' (probably not the right word) each reservation, determine the overlap, and show total usage.
The table is a list of reservations:
ResID StartTime EndTime SlotsUsed
1 2010-06-13 12:00:00 2010-06-13 12:59:00 10
2 2010-06-13 12:00:00 2010-06-13 12:29:00 5
3 2010-06-13 12:30:00 2010-06-13 13:29:00 15
And the output I want is something like this:
Time SlotsInUse
2010-06-13 12:00:00 15
2010-06-13 12:15:00 15
2010-06-13 12:30:00 25
2010-06-13 12:45:00 25
2010-06-13 13:00:00 15
Outside of SQL, I can do this pretty easily with date-time math & a list/array. But is there anyway to do it in the SELECT statement itself, somehow GROUPing items just right, and using sum()
?