在这种情况下,如何在 kdb 中编写正确的查询?
how do I write a proper query in kdb this case?
我想从我的 table 中获取所有价格为 0 的组,IE 仅当该组中所有价格均为 0 时才应返回。
我的查询和 table 看起来像这样。
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
输出应该仅为 `a
,因为 `a
是唯一一个所有价格都为 0 的组。
使用 fby
是实现此处结果的一种方法。
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
另一种方法:
q)where exec all 0=price by grp from tab
,`a
我想从我的 table 中获取所有价格为 0 的组,IE 仅当该组中所有价格均为 0 时才应返回。
我的查询和 table 看起来像这样。
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
输出应该仅为 `a
,因为 `a
是唯一一个所有价格都为 0 的组。
使用 fby
是实现此处结果的一种方法。
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
另一种方法:
q)where exec all 0=price by grp from tab
,`a