How can i get aggregated data of every 5th minute in last 10 mins in Mysql? -


i have table contains multiple data on same time interval every minute. want aggregate data of every 5th minute in last 10 mins. have tried solution provided on stack overflow not getting accurate data me none of them has tried data fix interval of time.

i using query :

select round(unix_timestamp(footable.createdtime)/(60 * 5)) timekey, avg(maindata) aggdata footable  footable.createdtime > date_sub(now(), interval 10 minute)  group timekey 

it should return max 2 records everytime of time returning 3 records.

note:- table contains data every minute confirmed , test condition 10 mins data of last hour. not duplicate question read description carefully.

any appreciated..!!

i figured out myself , below query solve issue :

set @timestmp := unix_timestamp(date_sub(now(), interval 10 minutes)); select @timestmp := if(((unix_timestamp(footable.createdtime) - @timestmp) >= 295), unix_timestamp(footable.createdtime),@timestmp) timekey, avg(maindata) aggdata footable  footable.createdtime > date_sub(now(), interval 10 minute)  group timekey 

this query give exact minute minute interval aggregated data on every execution. enjoy..!!


Comments