【问题标题】:how do I write a proper query in kdb this case?在这种情况下,如何在 kdb 中编写正确的查询?
【发布时间】:2021-03-09 17:41:40
【问题描述】:

我想从我的表中获取所有价格为 0 的组,仅当该组中的所有价格均为 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

输出只能是 `a,因为 `a 是唯一所有价格都为 0 的组。

【问题讨论】:

  • 您可以添加示例输入/输出吗?从最初的描述中很难准确理解您想要什么。

标签: kdb


【解决方案1】:

使用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

【讨论】:

    【解决方案2】:

    另一种方法:

    q)where exec all 0=price by grp from tab
    ,`a
    

    【讨论】:

      猜你喜欢
      • 2014-06-26
      • 1970-01-01
      • 2021-11-30
      • 1970-01-01
      • 1970-01-01
      • 2021-05-21
      • 2013-11-03
      • 2012-01-31
      • 1970-01-01
      相关资源
      最近更新 更多