I know that a few years after the initial question, but if you are dealing with larger datasets, this may take longer due to the call of two functions for each row in the query set.
I managed to shave a couple of seconds off my time using a bit of modular arithmetic
GROUP BY FLOOR(time_col/(60*60) MOD 24)
Hope this helps :)
source share