在这种情况下,如何在 kdb 中编写正确的查询?

Ter*_*rry 1 kdb

我想从我的表中获取所有价格为 0 的组,IE 仅当该组中的所有价格都为 0 时才应返回。

我的查询和表看起来像这样。

tab:([]grp:`a`b`c`c`a`a`a;price:0 20 0 1 0 0 0)
select grp from tab where distinct price = 0
Run Code Online (Sandbox Code Playgroud)

输出应该只是`a因为`a是唯一一个所有价格都为 0 的组。

Cat*_*ill 6

使用 anfby是在此处实现结果的一种方法。

q)tab:([]grp:`a`b`c`c`a`a`a;price:0 20 0 1 0 0 0)
q)select from tab where 0=(max;abs price)fby grp
grp price
---------
a   0
a   0
a   0
a   0
q)distinct exec grp from tab where 0=(max;abs price)fby grp
,`a
Run Code Online (Sandbox Code Playgroud)


ter*_*nch 5

另一种方法:

q)where exec all 0=price by grp from tab
,`a
Run Code Online (Sandbox Code Playgroud)