我收集了如下格式的tick数据
"instrument","tick_time","ask","bid","askVol","bidVol"
"EUR/USD","2011-07-24 20:00:01","1.43676","1.43666","1.13","4.13"
"EUR/USD","2011-07-24 20:00:02","1.43676","1.43666","1.13","4.5"
"EUR/USD","2011-07-24 20:00:03","1.43674","1.43664","1.13","1.65"
"EUR/USD","2011-07-24 20:00:06","1.43675","1.43665","1.13","5.4"
"EUR/USD","2011-07-24 20:00:06","1.43677","1.43668","1.13","4.28"
"EUR/USD","2011-07-24 20:00:10","1.43676","1.43666","1.13","6.15"
"EUR/USD","2011-07-24 20:00:11","1.43679","1.43669","1.13","4.13"
现在我试着用它来创造5分钟的酒吧。我尝试了下面的sql语句。
select ROUND(tick_time / (60*5)) * 60 * 5 as bar_time,
max(bid) as high,
min(bid) as low
from ticks
group by bar_time
我得到以下数据
"bar_time","high","low"
"20110724199900","1.43669","1.43661"
"20110724200200","1.4366","1.4358"
"20110724200500","1.43625","1.43579"
"20110724200800","1.4365","1.43608"
"20110724201100","1.43645","1.43601"
"20110724201400","1.43624","1.43573"
"20110724201700","1.43619","1.43591"
"20110724202000","1.43644","1.4359"
我该怎么做
是否以日期时间格式设置条形图时间?
将第一个和最后一个数据聚合为列。
最佳答案
其他解决方案:
select
date_format(
date_sub(
tick_time,
INTERVAL (extract(MINUTE from tick_time) % 5) MINUTE
),
"%m-%d%Y %H:%i"
) as bar_time,
MAX(bid) AS high,
MIN(bid) AS low
from ticks
group by bar_time
关于mysql - 5分钟使用mysql吧,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6939913/