I have the following table structure
ID | capacity | startDateTime
1 | 2 | 2013-11-26 13:23:23
2 | 3 | 2013-11-26 14:23:21
3 | 2 | 2013-11-26 13:44:44
4 | 6 | 2013-11-26 14:24:22
I am trying to get the count-of-IDs for categories-of-capacity grouped into hour and 30 minute intervals.
An example of my output is
Hour | Minute | Capacity1-2 | Capacity3-4 | Capacity5above
13 | 0 | 1 | 0 | 0
13 | 1 | 1 | 0 | 0
14 | 0 | 0 | 1 | 1
Minute=0 is for IDs with startDateTime before the 30th minute of the hour (e.g. 13:00:00 to 13:29:29) and Minute=1 is for IDs with `startDateTime after the 30th minute of the hour.
I have came as far as to writing something like this but it gives me the total transactions. I am having problems putting the category-of-capacity into separate columns.
SELECT HOUR(startDateTime) AS Hour,
FLOOR(MINUTE(startDateTime)/30) AS Minute,
COUNT(DISTINCT ID) as numTransactions
FROM transaction t
WHERE startDateTime >= '2013-11-26 00:00:00'
AND queueStartTime <= '2013-11-26 23:59:59'
GROUP BY HOUR(startDateTime), FLOOR(MINUTE(startDateTime)/30)