How do you select every n-hours in a timestamp column? I am able to do so with 1 hour by grouping:
SELECT log_timestamp
FROM log
GROUP BY
DATE( log_timestamp ),
HOUR( log_timestamp )
Returns:
log_timestamp
2015-11-08 00:00:01
2015-11-08 01:00:01
2015-11-08 02:00:01
2015-11-08 03:00:01
...
Any ideas for how to do this by 2 or more hours?
log_timestamp
2015-11-08 00:00:01
2015-11-08 02:00:01
2015-11-08 04:00:01
2015-11-08 06:00:01
...
You can use INTEGER DIVISION
:
SELECT L.log_timestamp
FROM log L
GROUP BY DATE( log_timestamp ), hour( log_timestamp ) DIV 2
SqlFiddleDemo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With