You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Kusto中按多列分区获取每组Top3销售负责人数据?

解决Kusto按多列组合分组取TopN的问题

你当前的脚本问题在于partition仅按product单字段分区,导致结果跨billable_id和organization_id统计,不符合按三者组合分组的需求。以下两种方法可以实现目标:

方法一:多列作为partition分区键

Kusto的partition函数支持同时指定多个分区字段,用逗号分隔即可。直接将billable_id、organization_id、product都加入partition by的列表,就能确保每个组合分组内单独取Top3:

table_1 
| where day >= ago(28d)
| summarize hint.strategy=shuffle max_sales=max(sales_amount) by billable_id, organization_id, product, account_executive_id
| partition hint.strategy=shuffle by billable_id, organization_id, product (
    top 3 by max_sales desc
)

方法二:使用窗口函数(更灵活)

如果需要更复杂的排名逻辑(比如处理并列排名),可以用row_number()/rank()/dense_rank()窗口函数,配合分区逻辑实现。如果数据量较大,先通过partition拆分再处理会更高效:

table_1 
| where day >= ago(28d)
| summarize max_sales=max(sales_amount) by billable_id, organization_id, product, account_executive_id
| partition hint.strategy=shuffle by billable_id, organization_id, product (
    extend rank = row_number() over (order by max_sales desc)
    | where rank <= 3
    | project-away rank
)

如果数据量不大,也可以省略partition直接在全局使用窗口函数:

table_1 
| where day >= ago(28d)
| summarize max_sales=max(sales_amount) by billable_id, organization_id, product, account_executive_id
| extend rank = row_number() over (partition by billable_id, organization_id, product order by max_sales desc)
| where rank <= 3
| project-away rank

内容的提问来源于stack exchange,提问作者SusanD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 21:27:46