如何在Kusto中​​的Summarize中添加额外的列

时间:2019-11-11 21:01:01

标签: kusto kusto-query-language kql

我是Kusto的新手,我正尝试使用summarize进行分组,在这里我可以指定其他列以显示要分组的值。

这是我正在尝试做的,在标准SQL中提到:

select UserId, LocationId, COUNT(*) as ErrorCount from SampleTable where ResultType != 'Success'
group by UserId
order by ErrorCount desc

我正在按UserId进行分组,但随后在分组结果中也显示了该LocationId的{​​{1}}

将以上内容转换为Kusto,我正在写:

UserId

但是它不起作用。 Kusto抱怨无法确定SampleTable | where ResultType != "Success" | summarize ErrorCount=count() by UserId | project UserId, LocationId, ErrorCount | sort by ErrorCount desc 是否在第四行。我使用Kusto的LocationId关键字验证了我在编写正确的Kusto查询。那是什么问题呢?

2 个答案:

答案 0 :(得分:3)

如果要将LocationId作为聚合键之一,则应将其包括在对summarize的调用中,如下所示:| summarize ErrorCount = count() by UserId, LocationId

[否则,请阐明您期望的输出模式(理想情况下,除了使用datatable运算符提供示例输入数据集:https://docs.microsoft.com/en-us/azure/kusto/query/datatableoperator)]

答案 1 :(得分:1)

只是对您原始SQL代码的友好提醒

select UserId, LocationId, COUNT(*) as ErrorCount from SampleTable where ResultType != 
'Success'
group by UserId
order by ErrorCount desc

其中可能包含错误:

GROUP BY子句中缺少

LocationId

正确的SQL代码应为:

select UserId, LocationId, COUNT(*) as ErrorCount from SampleTable where ResultType != 
'Success'
group by UserId, LocationId
order by ErrorCount desc

我认为这可能是您在Kusto代码中的summary子句中意外错过LocationId的原因。