我怎样才能过滤掉除最新元素之外的所有元素?
How can I filter out all elements except the newest ones?
我想做一些看似简单但很难确定如何在 KQL 中完成的事情。假设您有一个包含 DateTime 列的结果集。我想要一个只保留具有最新 DateTime 的行的 Kusto 查询。
所以对于这样的结果集:
Person
Ingestion DateTime
Bob
11/12/2021 9 AM
Sam
11/12/2021 10 AM
William
11/12/2021 11 AM
Kate
11/12/2021 3 PM
Aria
11/12/2021 3 PM
Ben
11/9/2021 4 AM
我想要一个删除除 Kate 和 Aria 之外的所有行的查询,因为它们在结果集中都有最新的 DateTime。
我一直在尝试总结 max() ,它似乎对 DateTimes 进行了分组,但没有过滤掉旧的。有没有先排序再筛选的方法?
您可以有一个子查询来计算等于最大日期时间值的标量值,然后使用该标量值进行过滤。
例如:
datatable(Person:string, IngestionDateTime:datetime)
[
'Bob', datetime(11/12/2021 09:00),
'Sam', datetime(11/12/2021 10:00),
'William', datetime(11/12/2021 11:00),
'Kate', datetime(11/12/2021 15:00),
'Aria', datetime(11/12/2021 15:00),
'Ben', datetime(11/9/2021 04:00)
]
| as T
| where IngestionDateTime == toscalar(T | summarize max(IngestionDateTime))
Person
IngestionDateTime
Kate
2021-11-12 15:00:00.0000000
Aria
2021-11-12 15:00:00.0000000
我想做一些看似简单但很难确定如何在 KQL 中完成的事情。假设您有一个包含 DateTime 列的结果集。我想要一个只保留具有最新 DateTime 的行的 Kusto 查询。
所以对于这样的结果集:
Person | Ingestion DateTime |
---|---|
Bob | 11/12/2021 9 AM |
Sam | 11/12/2021 10 AM |
William | 11/12/2021 11 AM |
Kate | 11/12/2021 3 PM |
Aria | 11/12/2021 3 PM |
Ben | 11/9/2021 4 AM |
我想要一个删除除 Kate 和 Aria 之外的所有行的查询,因为它们在结果集中都有最新的 DateTime。
我一直在尝试总结 max() ,它似乎对 DateTimes 进行了分组,但没有过滤掉旧的。有没有先排序再筛选的方法?
您可以有一个子查询来计算等于最大日期时间值的标量值,然后使用该标量值进行过滤。
例如:
datatable(Person:string, IngestionDateTime:datetime)
[
'Bob', datetime(11/12/2021 09:00),
'Sam', datetime(11/12/2021 10:00),
'William', datetime(11/12/2021 11:00),
'Kate', datetime(11/12/2021 15:00),
'Aria', datetime(11/12/2021 15:00),
'Ben', datetime(11/9/2021 04:00)
]
| as T
| where IngestionDateTime == toscalar(T | summarize max(IngestionDateTime))
Person | IngestionDateTime |
---|---|
Kate | 2021-11-12 15:00:00.0000000 |
Aria | 2021-11-12 15:00:00.0000000 |