【问题标题】:Kusto / KQL query to take distinct output and then use in subsequent queryKusto / KQL 查询获取不同的输出,然后在后续查询中使用
【发布时间】:2021-06-18 21:41:03
【问题描述】:

我在customMetrics 表中有以下数据:

| date       | customDimension  | Type         | value |
| -----------------------------------------------------|
| 01-03-2021 | {"customer":"a"} | Transactions | 12    |
| 01-03-2021 | {"customer":"a"} | Value        | 784   |
| 01-03-2021 | {"customer":"c"} | Transactions | 733   |
| 01-03-2021 | {"customer":"b"} | Transactions | 7     |
| 01-03-2021 | {"customer":"c"} | Value        | 5     |
| 01-03-2021 | {"customer":"b"} | Value        | 85    |
| 01-03-2021 | {"customer":"a"} | Transactions | 50    |
| 01-03-2021 | {"customer":"a"} | Value        | 73    |
| 01-03-2021 | {"customer":"c"} | Value        | 3     |
| 01-03-2021 | {"customer":"a"} | Transactions | 13    |
| 01-03-2021 | {"customer":"a"} | Value        | 237   |
| 01-03-2021 | {"customer":"c"} | Transactions | 3     |
| 01-03-2021 | {"customer":"b"} | Transactions | 575   |
| 01-03-2021 | {"customer":"b"} | Value        | 85    |
| 01-03-2021 | {"customer":"b"} | Transactions | 43    |
| 01-03-2021 | {"customer":"b"} | Value        | 85    |
| 01-03-2021 | {"customer":"c"} | Value        | 789   |

我正在尝试编写一个查询,该查询将为每个客户找到每种类型的每个值的最大值,例如类似:

| date       | customer | Type         | value |
| ---------------------------------------------|
| 01-03-2021 | a        | Transactions | 50    |
| 01-03-2021 | a        | Value        | 784   |
| 01-03-2021 | b        | Transactions | 575   |
| 01-03-2021 | b        | Value        | 85    |
| 01-03-2021 | c        | Transactions | 733   |
| 01-03-2021 | c        | Value        | 789   |

我很难知道在 kusto 中搜索什么概念来执行此类操作。我可以获得不同的客户列表和不同的类型列表,但我不确定如何将两者结合起来,或者这是否是我应该做的!

任何线索都会有所帮助!

【问题讨论】:

    标签: azure-data-explorer kql


    【解决方案1】:

    使用summarize arg_max(...) by Type, Customer 就可以了。

    在 arg_max here 上查看更多信息。

    【讨论】:

    • 谢谢,我正在使用它,但它会找到类型列的最大值,而不是每个客户的每种类型的最大值
    • 只需将这些添加到“by”子句中
    • 对,就像@Avnera 写的那样,您可以在by 之后放置多个列名,所以我更新了我的答案以更具体。
    猜你喜欢
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 2014-11-15
    • 2019-05-05
    • 2017-08-30
    相关资源
    最近更新 更多