KQL使用top-nested按目的地统计Top3来源及对应路径总访问量
KQL实现按目的地分组取Top3来源并统计访问量
最优实现方案(partition算子)
TransportData // 统计每个<目的地, 来源>路径的总访问量 | summarize TotalVisits = count() by Destination, Source // 按目的地分组,每组内按访问量降序取前3条 | partition by Destination ( top 3 by TotalVisits desc ) // 可选:对最终结果按目的地、访问量排序,更易读 | order by Destination asc, TotalVisits desc
如果需要保留并列排名的来源,可以将top 3修改为top 3 with ties
基于top-nested的修正方案
你之前用top-nested没拿到总访问量是因为没有显式将计数赋值给对应字段,修正后写法如下:
TransportData | top-nested of Destination by max(1), // 此处可指定目的地数量,如`top-nested 50 of Destination` top-nested 3 of Source by TotalVisits = count() | project Destination, Source, TotalVisits
这个方案更适合目的地数量大的大数据量查询场景。
内容的提问来源于stack exchange,提问作者Edelweiss Peimann
相关产品推荐
相关产品推荐

