【问题标题】:How to add extra column in Summarize in Kusto如何在 Kusto 的 Summarize 中添加额外的列
【发布时间】:2019-11-11 21:01:01
【问题描述】:

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

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

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

我按UserId 分组,但随后我也在分组结果中显示LocationIdUserId

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

SampleTable
| where ResultType != "Success"
| summarize ErrorCount=count() by UserId
| project UserId, LocationId, ErrorCount
| sort by ErrorCount desc

但它不起作用。 Kusto 抱怨它无法确定 LocationId 是否在第 4 行。我使用 Kusto 的 explain 关键字验证了我正在编写正确的 Kusto 查询。那么有什么问题呢?

【问题讨论】:

    标签: azure-data-explorer kql


    【解决方案1】:

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

    [否则,请说明您期望的输出模式(理想情况下,在提供示例输入数据集的同时,使用datatable 运算符:datatable operator

    【讨论】:

    • 这让我所有的梦想都成真了。谢谢!
    【解决方案2】:

    只是友情提醒你原来的 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 代码的汇总子句中意外遗漏 LocationId 的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      • 2019-11-12
      • 1970-01-01
      • 2015-10-07
      • 1970-01-01
      • 2022-10-15
      相关资源
      最近更新 更多