如何在kdb where查询中使用多个参数?

如何在kdb where查询中使用多个参数?,kdb,Kdb,我想在接下来的5、10、30分钟内从表中选择最大元素。 我怀疑where子句中的多个元素不可能实现这一点。 使用普通的您可以尝试以下方法: select c1:max price[where time <09:05:00],c2:max price[where time <09:10:00],c3:max price from dat where time< 09:30:00 选择c1:max price[其中time有效,但需要很多时间。对于20k条记录,~20秒,太多了!

我想在接下来的5、10、30分钟内从表中选择最大元素。 我怀疑where子句中的多个元素不可能实现这一点。
使用普通的
您可以尝试以下方法:

select c1:max price[where time <09:05:00],c2:max price[where time <09:10:00],c3:max price from dat where time< 09:30:00

选择c1:max price[其中time有效,但需要很多时间。对于20k条记录,~20秒,太多了!有没有办法让它更快

 dat: update tmlst: time+\:mtf*60 from dat;
 dat[`pxs]: {[x;y] {[x; ts] raze flip raze {[x;y] select min price from x where time<y}[x] each ts }[x; y`tmlst]} [dat] each dat;
dat:从dat更新tmlst:time+\:mtf*60;

dat[`pxs]:{[x;y]{[x;ts]raze flip raze{[x;y]从x中选择最小价格,其中时间这构造了一个步骤字典,将时间映射到您的存储桶:

q)-1_select max price by(`s#{((neg w),x)!x,w:(type x)$0W}09:05:00 09:10:00 09:30:00)time from dat
您还可以滥用:

如果所有水桶的大小相同,则更容易:

q)select max price by 300 xbar time from dat where time<09:30:00 / 300-second (5-min) buckets

q)从dat中选择300 xbar时间的最大价格,其中时间正是我试图避免的。如果我必须为5、10、20、25、30、35……等等做些什么,这个解决方案并不理想f的用途是什么?尝试f[(15 30 60 120)],它只是在单独的列中给出了4个值,而不是我想要的。我意识到问题的原始范围是用您的方法回答的。我已经编辑以再次扩展问题的范围,答案只返回到0930的常量桶。我想对表中的所有行执行此操作。对于每次x,我想计算最大pri在x+5、x+15、x+30…分钟后执行ce。
 dat: update tmlst: time+\:mtf*60 from dat;
 dat[`pxs]: {[x;y] {[x; ts] raze flip raze {[x;y] select min price from x where time<y}[x] each ts }[x; y`tmlst]} [dat] each dat;
q)-1_select max price by(`s#{((neg w),x)!x,w:(type x)$0W}09:05:00 09:10:00 09:30:00)time from dat
q)wj[{(prev x;x)}09:05:00 09:10:00 09:30:00;`time;([]time:09:05:00 09:10:00 09:30:00);(delete sym from dat;(max;`price))]
q)select max price by 300 xbar time from dat where time<09:30:00 / 300-second (5-min) buckets