过滤具有基于 kdb 中其他标量列的行列表的列

问题描述 投票:0回答:1
w:(1 2;3 4;5 2); l:til count w; h:l+1;
show t:([] l; h; w);

l h w  
-------
0 1 1 2
1 2 3 4
2 3 5 2

我有一个表

t
,其中有一列
w
,其中包含行列表。我只想保留
w
的每一行中位于表格每行的
l
h
值之间的元素。

预期输出是:

l h w  
-------
0 1 ,1
1 2 ,
2 3 ,2

我尝试过做

t:update w:w[where ((w>=l) and (w<=h))] from t;

但是失败了

'type
  [0]  t:update w:w[where ((w>=l) and (w<=h))] from t;

kdb
1个回答
0
投票

您可以使用

within
https://code.kx.com/q/ref/within

q)update w:w@'where each w within(l;h)from t
l h w
------------
0 1 ,1
1 2 `long$()
2 3 ,2

您最初的尝试已经接近,这是更正后的版本:

q)update w:w@'where each(w>=l)and w<=h from t
l h w
------------
0 1 ,1
1 2 `long$()
2 3 ,2

您需要将表列视为列表(因此您需要

each
和each-both (
'
) 迭代器。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.