Reputation: 31
I have a table with the MYSQL default Timestamp value.
I want to get the count of data grouped by intervals of 5 minutes for the last 1 hour precisely such that I get [24,65,85,12,32,45,68]
24 are the number of records that were created in the last 5 minutes.
Upvotes: 0
Views: 458
Reputation: 1270021
Assuming you have data for each 5 minute period, you can use aggregation:
select floor(timestampdiff(minute, timestamp, now()) / 5) * 5 as mins,
count(*)
from t
where t.timestamp >= now() - interval 1 hour
group by mins;
Upvotes: 1