GROUP BY UNIX_TIMESTAMP(time_stamp) DIV 30
or say for some reason you wanted to group them in 20-second intervals it would be DIV 20
etc. To change the boundaries between GROUP BY
values you could use
GROUP BY (UNIX_TIMESTAMP(time_stamp) + r) DIV 30
where r
is a literal nonnegative integer less than 30. So
GROUP BY (UNIX_TIMESTAMP(time_stamp) + 5) DIV 30
should give you sums between hh:mm:05 and hh:mm:35 and between hh:mm:35 and hh:mm+1:05.