DolphinDB针对时序数据处理,在SQL中增加了一个context by子句,也就是说数据先按照context by后面指定的字段进行分组,每一个组内部再应用序列函数。
上面的例子其实已经使用了context by,只不过只按照股票一个字段进行分组,再增加一个日期字段即可。
n_move=5 t1= select concatDateTime(trade_date,trade_time) as time,secu_code, (close/close.move(n_move))-1 as r_close, //等价于ratios(close)-1 (volume/volume.move(n_move))-1 as r_volume, (turnover/turnover.move(n_move))-1 as r_turnover from quote_1min where trade_date between date_begin:date_end context by secu_code, trade_date