Skip to content Skip to sidebar Skip to footer

Mysql Window Function To Calculate Averages Or Maximums Every 5 Minutes

I have a table data with columns clock (unixtime) and value, where records appear every 50-70 seconds. I need to draw a monthly graph that reflects the maximum (or average) values

Solution 1:

There are 300 seconds in five minutes. So you can use arithmetic to aggregate the results:

SELECT (FLOOR(clock /300) *300) as period_start,
       MIN(clock), MAX(clock), AVG(value)
FROM data 
WHERE clock BETWEEN1622667600AND1625259600GROUPBYFLOOR(clock /300);

I don't know if you want the WHERE clause, but I left it in.

Post a Comment for "Mysql Window Function To Calculate Averages Or Maximums Every 5 Minutes"