kql - 对聚合上下文中列的引用可能不会出现在聚合函数之外
问题描述
我需要构建一个查询,计算一个类别的每个值(在本例中为策略)在不同时间段的总运行中所占的百分比。我想出了以下查询,但是出现语法错误:
语义错误:在聚合上下文中对列“总计”的引用可能不会出现在聚合函数之外。
requests
| where timestamp between (startTime..endTime)
| extend strategy = tostring(customDimensions.QueryStrategy)
| summarize count() by strategy, bin(timestamp, 30m)
| join (requests
| where timestamp between (startTime..endTime)
| summarize total = count() by bin(timestamp, 30m)) on timestamp
| project timestamp, strategy, count_, total = toint(total)
| summarize 100 *count()/total by strategy, timestamp
解决方案
这是实现您想要的正确方法:
// The following table literally represents a long calculation
// that ends up with an anonymous tabular value:
datatable (SomeInt:int, SomeSeries:string) [
100, "Apple",
200, "Banana",
]
// We now give this calculation a name ("X"):
| as X
// Having this name we can refer to it in the sub-expression
// "X | summarize sum(SomeInt)":
| extend Pct = 100 * bin(todouble(SomeInt) / toscalar(X | summarize sum(SomeInt)), 0.001)
推荐阅读
- visual-studio-2017 - VS SQL 单元测试项目上的“无法访问已处理的对象”错误
- windows - 离线部署 NPM 文件到工件
- django - Django将未登录用户重定向到登录页面
- java - 扩展一个没有构造函数的类
- python - 如何检查我的字符串在python中是否为空
- list - 如何从 R 中的 mapply 或 Map 函数中的数据列表中选择 2 个变量?
- mysql - 无法使用 JOIN 更新特定记录
- r - drv <- dbDriver("Oracle") 在命令行 R 中工作正常,但在 RStudio Server 上不工作
- java - 面向对象编程 - 两种方式组合实践?
- c++ - 创建数组并从中检索数据时 C++ 中的未定义行为