Consider the following table:
msg_id _time
-------------
1 13:32
2 13:56
3 14:05
4 15:00
5 15:17
6 15:28
7 16:40
I’m currently aggregating the number of messages per hour, as follows:
SELECT HOUR(_time) AS hour, COUNT(msg_id) AS cnt FROM messages GROUP BY hour
ORDER BY hour
This results in a resultset as follows:
hour cnt
---------
13 2
14 1
15 3
16 1
What I want, however, is the count per half hour:
hour cnt
----------
13:30 2
14:00 1
14:30 0
15:00 3
15:30 0
16:00 0
16:30 1
What is the query making this possible? If necessary, I guess I could mkae a table with the half-hour times (00:00, 00:30, 01:00, 01:30, … 23:00, 23:30), but prefer not too. (And I still wouldn’t know how to use that table either).
Any help is greatly appreciated 🙂
you can use
case when