汇总Azure(Kusto查询语言)中的多列

时间:2019-11-04 09:52:59

标签: azure pivot kusto kusto-query-language

我在Azure监视器日志中具有以下格式的点击流数据:

Category   StepName     Count_    Median_Duration(secs)
   A         step1       1200        00:00
   A         step2       1000        24:00
   A         step3        800        19:00
   B         step1       4000        00:00
   B         step2       3800        37:00

我需要旋转表以获得此信息:

Category Step1_Count Step1_Duration Step2_Count Step2_Duration Step3_Count ...
   A       1200          00:00         1000        24:00          800      ...
   B       4000          00:00         3800        37:00           0       ...

现在,我只能使用评估数据透视表(StepName,sum(Count_))或评估数据透视表(StepName,sum(Median_Duration))来汇总一列。是否可以在不使用联接的情况下获得上述格式?

注意:与输出表类似的格式很好,只需要计数和持续时间的总和即可。

1 个答案:

答案 0 :(得分:1)

您可以尝试以下方法:

datatable(Category:string, StepName:string, Count_:long, Median_Duration:timespan)
[
   "A", "step1", 1200, time(00:00:00),
   "A", "step2", 1000, time(00:00:24),
   "A", "step3",  800, time(00:00:19),
   "B", "step1", 4000, time(00:00:00),
   "B", "step2", 3800, time(00:00:37),
]
| summarize StepCount = sum(Count_), Duration = avg(Median_Duration) by Category, StepName
| project Category, p = pack(strcat(StepName, "_Count"), StepCount, strcat(StepName, "_Duration"), Duration)
| summarize b = make_bag(p) by Category
| evaluate bag_unpack(b)

或者,如果您可以使用其他输出模式,则可以:

datatable(Category:string, StepName:string, Count_:long, Median_Duration:timespan)
[
   "A", "step1", 1200, time(00:00:00),
   "A", "step2", 1000, time(00:00:24),
   "A", "step3",  800, time(00:00:19),
   "B", "step1", 4000, time(00:00:00),
   "B", "step2", 3800, time(00:00:37),
]
| summarize StepCount = sum(Count_), Duration = avg(Median_Duration) by Category, StepName