我是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查询。那是什么问题呢?
答案 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的原因。