Kusto查询过去3天的数据,对于那天没有数据,设置为0。

huangapple go评论52阅读模式
英文:

Kusto query Past 3 days data with setting 0 for no data for that date

问题

第一次尝试使用KQL,希望有人能帮助我。
我需要过去三天内,每天每个用户的事件计数,与创建日期相关。

结果应该类似于:

创建日期 用户 计数
2023年05月31日 Ali 1
2023年05月30日 Ali 0
2023年05月29日 Ali 2
2023年05月31日 Ken 1
2023年05月30日 Ken 2
2023年05月29日 Ken 0

如果某天没有数据,请将计数设置为0。我尝试了以下代码:

    events
    | where created >= ago(3d)  
    | summarize Count = count() by created = bin(created, 1d), user
    | project created = format_datetime(created, 'dd/MM/yyyy'), user, Count
    | order by created desc

但是如何为没有数据的那一天填充0呢?

英文:

First time trying kql, hope someone could help me.
I need past 3 days of each day event count with respect to created date and by each of the user.

Result would be something like:

Created User Count
31/05/2023 Ali 1
30/05/2023 Ali 0
29/05/2023 Ali 2
31/05/2023 Ken 1
30/05/2023 Ken 2
29/05/2023 Ken 0

If there is no data on that day, put 0 as the count. I tried something like:

events
| where created >= ago(3d)  
| summarize Count = count() by created = bin(created, 1d), user
| project created = format_datetime(created, 'dd/MM/yyyy'), user, Count
| order by created desc

But how can i fill the 0 for the count for the day that has no data?

答案1

得分: 2

你可以考虑使用 make-series 运算符,而不是使用 summarize 运算符。

英文:

You can consider using the make-series operator instead of the summarize operator

huangapple
  • 本文由 发表于 2023年6月1日 10:55:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76378395.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定