KDB:在“周围"选择数据某些事件的时间 [英] KDB:selecting data "around" time of certain events

查看:72
本文介绍了KDB:在“周围"选择数据某些事件的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑巨大的市场数据表T.我对Status =`SSS的行特别感兴趣.

Consider a huge table of market data T. I am particularly interested in rows where Status=`SSS.

但是,除了给定的行(从T中选择Status =`SSS的行)之外,我还想选择紧接在这些行之前和之后的10条记录. (请注意,在某些情况下,这些间隔可能会重叠).什么是有效的方法?

However, in addition to the rows given by (select from T where Status=`SSS), I also would like to select the 10 records that come both immediately before and after these rows. (Note that in some cases, these intervals may overlap). What is an efficient way to do this?

请注意,我在下面尝试了类似的操作,它几乎使我的端口崩溃并占用了所有内存.

Note that I tried something like this below, and it nearly crashed my port and hogged up all the memory.

select from
update diff:min each abs i-(count i)# enlist (exec distinct x from select from
(update x:i from T) where Status=`SSS),where diff<10 

推荐答案

这里是WooiKent答案中几乎没有修改的另一种解决方案.但是随着时间和空间的推移,它有了一些改进.

Here is another solution with little modification in WooiKent answer. But it gives some improvement over time and space.

select from t where i in distinct raze (-10+til 21)+\:(exec i from t where sym=`CC)

对于WooiKent示例表:

For WooiKent sample table:

\ts select from t where i in distinct raze (-10+til 21)+\:(exec i from t where sym=`CC)
113 77595968j

这篇关于KDB:在“周围"选择数据某些事件的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆