Kusto 查询获取每个 Y 中具有最大 Z 的 X
Kusto query get the X in each Y with max Z
我正在尝试编写一个 Kusto 查询以获取每个 [y] 中的 [x],其中 [z] 最多。更具体地说,我正在查询 Azure 数据资源管理器示例 table Covid 以查找每个国家/地区死亡人数最多的州。我试过这个:
Covid19
| where State <> ""
| summarize deaths = max(Deaths) by State, Country
| project Country, State, deaths
| order by deaths
运行,但产生来自同一个国家的多个州。我也试过这个:
Covid19
| where State <> ""
| summarize deaths = max(Deaths) by State, Country
| summarize deths = max(deaths) by State
| project Country, State, deths
但最后一行出现错误“名称 'Country' 未引用任何已知列...”。
我也试过这个:
Covid19
| where State <> ""
| summarize deaths = max(Deaths) by State, Country
| summarize deths = max(deaths) by Country
| project Country, deths
这似乎产生了正确的结果,但我无法显示状态。所以我好像遇到了一个问题,我的信息要么太多要么不够。
第一个查询的实际结果:
预期结果:
您可以尝试使用 top-nested
运算符:https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/topnestedoperator
Covid19
| where isnotempty(State)
| top-nested of Country by max(1), top-nested 1 of State by max(Deaths)
| project Country, State, deaths = aggregated_State
| order by deaths
或者,如果您想要更“自然”/“直观”的语法(正如您在评论中所述),您可以使用 arg_max()
:https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/arg-max-aggfunction
Covid19
| where isnotempty(State)
| summarize arg_max(deaths, *) by Country
| order by deaths
我发现我可以为此使用 arg_max,我认为这是最简单的方法
Covid19
| where isnotempty(State)
| summarize arg_max(Deaths, State) by Country
指定输出顺序:
Covid19
| where isnotempty(State)
| summarize arg_max(Deaths, State) by Country
| order by Deaths
| project Country, State, Deaths
我正在尝试编写一个 Kusto 查询以获取每个 [y] 中的 [x],其中 [z] 最多。更具体地说,我正在查询 Azure 数据资源管理器示例 table Covid 以查找每个国家/地区死亡人数最多的州。我试过这个:
Covid19
| where State <> ""
| summarize deaths = max(Deaths) by State, Country
| project Country, State, deaths
| order by deaths
运行,但产生来自同一个国家的多个州。我也试过这个:
Covid19
| where State <> ""
| summarize deaths = max(Deaths) by State, Country
| summarize deths = max(deaths) by State
| project Country, State, deths
但最后一行出现错误“名称 'Country' 未引用任何已知列...”。
我也试过这个:
Covid19
| where State <> ""
| summarize deaths = max(Deaths) by State, Country
| summarize deths = max(deaths) by Country
| project Country, deths
这似乎产生了正确的结果,但我无法显示状态。所以我好像遇到了一个问题,我的信息要么太多要么不够。
第一个查询的实际结果:
预期结果:
您可以尝试使用 top-nested
运算符:https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/topnestedoperator
Covid19
| where isnotempty(State)
| top-nested of Country by max(1), top-nested 1 of State by max(Deaths)
| project Country, State, deaths = aggregated_State
| order by deaths
或者,如果您想要更“自然”/“直观”的语法(正如您在评论中所述),您可以使用 arg_max()
:https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/arg-max-aggfunction
Covid19
| where isnotempty(State)
| summarize arg_max(deaths, *) by Country
| order by deaths
我发现我可以为此使用 arg_max,我认为这是最简单的方法
Covid19
| where isnotempty(State)
| summarize arg_max(Deaths, State) by Country
指定输出顺序:
Covid19
| where isnotempty(State)
| summarize arg_max(Deaths, State) by Country
| order by Deaths
| project Country, State, Deaths