gsiener gsiener -4 years ago 274
SQL Question

Group mysql query by 15 min intervals

I've got a monitoring system that is collecting data every n seconds (n ~=10 but varies). I'd like to aggregate the collected data by 15 minute intervals. Is there a way to corral the timestamp column into 15 minute chunks to allow for grouping to work?

Answer Source
SELECT   ROUND(UNIX_TIMESTAMP(timestamp)/(15 * 60)) AS timekey
FROM     table
GROUP BY timekey;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download