SecurityId = `C`MS`MS`MS`IBM`IBM`C`C`C$SYMBOL
date = 2012.06.01 2012.06.01 2012.06.02 2012.06.03 2012.06.01 2012.06.02 2012.06.02 2012.06.03 2012.06.04
tradeMoney = 49.6 29.46 29.52 30.02 174.97 175.23 50.76 50.32 51.29
t = table(SecurityId,date,tradeMoney)
filter = select percentile(tradeMoney, 95) as min, max(tradeMoney) as max from t group by SecurityId//每只股票前5%的范围
filterMap = dict(filter.SecurityId, each(pair, filter.min, filter.max))//字典形式表示每只股票的查询范围
select avg(tradeMoney),std(tradeMoney), min(tradeMoney) from t where conditionalFilter(tradeMoney, SecurityId, filterMap) group by SecurityId
如果按照股票分组SecurityID去计算循环,会比较慢。
可以参照以下写法: