我的数据源是“元数据”。每个设备都有唯一的ID,并且每天可以多次签入。我想提出一个Kusto查询,该查询在过去30天内每天为每个deviceID返回一条记录。这是我目前的公式:
Metadata
| project-rename['Metadata.deviceID']=deviceID, ['Metadata.appName']=appName, ['Metadata.appVersion']=appVersion, ['Metadata.timeZone']=timeZone
| where (dateTimeUtc >= __sql_substract(now(), 30))
| summarize appName=max(['Metadata.appName']), deviceID=max(['Metadata.deviceID']), appVersion=max(['Metadata.appVersion']), timeZone=max(['Metadata.timeZone']) by bin(dateTimeUtc, 1d)
| project dateTimeUtc, appName, appVersion, timeZone, deviceID
每天返回1条记录,而不是每个deviceID每天返回1条记录。如果删除bin()并仅使用“ by dateTimeUtc”,则每个deviceID每天返回多个记录。 如何在过去30天内每天为每个deviceID获得一条记录?
答案 0 :(得分:2)
这会为您带来理想的结果吗?
(使用arg_max():https://docs.microsoft.com/en-us/azure/kusto/query/arg-max-aggfunction)
let Metadata = datatable(deviceID:string, appName:string, appVersion:string, timeZone:string, dateTimeUtc:datetime)
[
"d1", "a1", "v1", "PST", datetime(2018-12-01 15:53),
"d1", "a2", "v2", "PST", datetime(2018-12-01 12:01),
"d1", "a1", "v3", "UTC", datetime(2018-12-03 16:47:22),
"d1", "a2", "v4", "PST", datetime(2018-12-03 14:34:22),
"d2", "a2", "v2", "UTC", datetime(2018-11-30 15:54:22),
"d2", "a1", "v3", "PST", datetime(2018-11-30 14:53:22),
"d2", "a2", "v4", "UTC", datetime(2018-12-01 15:52:22),
"d2", "a1", "v1", "PST", datetime(2018-12-01 12:51:22)
];
Metadata
| where dateTimeUtc > ago(30d)
| summarize arg_max(dateTimeUtc, *) by deviceID, startofday(dateTimeUtc)
| project-away dateTimeUtc1