I need to group stockmarket \"1min\" data with {Name, DateTime, Open, High, Low, Close, Volume} into different timeframes ie. \"5mins/15mins/60mins\" on MYSQL. Schema built
I found that the solution of @Ruslan doesn't work in latest versions of MySQL so posting a version that works:
select
date_add(str_to_date(date_format(ev.startdatetime, '%Y-%m-%d'),'%Y-%m-%d'), interval
hour(ev.startdatetime)*60 + floor(minute(ev.startdatetime)/5)*5 minute) timeframe
, sum(ev.volume) volume
, min(ev.startdatetime) mintime
, substring_index(group_concat(open),',',1) open
, max(high) as high
, min(low) as low
, substring_index(group_concat(close),',',-1) close
from es1min_v ev
group by
date_add(str_to_date(date_format(ev.startdatetime, '%Y-%m-%d'),'%Y-%m-%d'), interval
hour(ev.startdatetime)*60 + floor(minute(ev.startdatetime)/5)*5 minute)