azure-application-insights - Power M Query/Kusto 从组中取第一

标签 azure-application-insights azure-data-explorer

我有一张看起来像这样的表:

id  timestamp  value1  value2
 1  09:12:37     1       1
 1  09:12:42     1       2
 1  09:12:41     1       3
 1  10:52:16     2       4
 1  10:52:18     2       5
 2  09:33:12     3       1
 2  09:33:15     3       2
 2  09:33:13     3       3

我需要按 id 和 value1 分组。对于每个组,我想要具有最高时间戳的行。

上表的结果如下所示:
id  timestamp  value1  value2
 1  09:12:42     1       2
 2  09:33:15     3       2

我知道有一个汇总运算符会给我这个:
mytable
| project id, timestamp, value1, value2
| summarize max(timestamp) by id, value1

Result:
     id  timestamp  value1
      1  09:12:42     1
      2  09:33:15     3

但是我也无法获得此行的 value2。

提前致谢

最佳答案

如果我正确理解您的问题,您应该可以使用 summarize arg_max() :

文档:https://docs.microsoft.com/en-us/azure/kusto/query/arg-max-aggfunction

datatable(id:long, timestamp:datetime, value1:long, value2:long)
[
 1, datetime(2019-03-20 09:12:37), 1, 1,
 1, datetime(2019-03-20 09:12:42), 1, 2,
 1, datetime(2019-03-20 09:12:41), 1, 3,
 1, datetime(2019-03-20 10:52:16), 2, 4,
 1, datetime(2019-03-20 10:52:18), 2, 5, // this has the latest timestamp for id == 1
 2, datetime(2019-03-20 09:33:12), 3, 1,
 2, datetime(2019-03-20 09:33:15), 3, 2, // this has the latest timestamp for id == 2
 2, datetime(2019-03-20 09:33:13), 3, 3,
]
| summarize arg_max(timestamp, *) by id

这将导致:
| id | timestamp                   | value1 | value2 |
|----|-----------------------------|--------|--------|
| 2  | 2019-03-20 09:33:15.0000000 | 3      | 2      |
| 1  | 2019-03-20 10:52:18.0000000 | 2      | 5      |

关于azure-application-insights - Power M Query/Kusto 从组中取第一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55260787/

相关文章:

azure - Azure Application Insights 中的持续时间范围

java - Application Insights Log4j 按日志文件名筛选

Azure Monitor(Application Insights)日志查询图表 - Y 轴上有什么?

azure-data-explorer - KQL,同一表中不同行之间的时间差

Azure 数据资源管理器 (ADX) 与 Polybase 与 Databricks

entity-framework - Azure 数据资源管理器 C# 查询和 ORM

azure - Application Insights 不记录成功的请求

azure - azure 应用程序服务中的响应时间出现异常峰值

azure - 在 Azure 中的何处添加监视读取器角色

azure - 如何加入最近的(较低日期)