我想从我的表中获取所有价格为 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 的组。
使用 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)