Group OHLC-Stockmarket Data into multiple timeframes - Mysql

后端 未结 4 1380
死守一世寂寞
死守一世寂寞 2021-01-01 00:52

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

4条回答
  •  太阳男子
    2021-01-01 01:30

    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) 
    

提交回复
热议问题