sql - Aggregating/Grouping a set of rows/records in MySQL -


i have table "sample" saves new record each 5 minutes. users might ask data collected specific sampling interval of 10 min or 30 min or hour.

since have record every 5 minutes, when user asks data hour sample interval, have club/group every 12 (60/5) records in 1 record (already sorted based on time-stamp), , criteria either min/max/avg/last value.

i trying in java once fetch records, , seeing pretty bad performance have iterate through collection multiple times, have read of other alternatives jagg , lambdaj, wanted check if that's possible in sql (mysql) itself.

the sampling interval dynamic , aggregation function (min/max/avg/last) user provided.

any pointers ?

you can in sql, have construct statement. here example hour 4 aggregations:

select min(datetime) datetime,        min(val) minval, max(val) maxval, avg(val) avgval,        substring_index(group_concat(val order datetime desc), ',', 1) lastval table t group floor(to_seconds(datetime) / (60*60)); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -