我正在尝试在 KQL 上编写一个带有变量的查询。这是它的第一部分:
我想在其他查询中使用它来添加一个包含每个事件总数百分比的列。换句话说,百分比 = EventNumber / totalEvents。
这是我的第二个查询:
但是当我尝试合并查询时出现错误。你能帮我解决这个问题吗?
您可以尝试使用toscalar()
:https ://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/toscalarfunction
例如:
let total_events = toscalar(
T
| where Timestamp > ago(7d)
| count
);
T
| where Timestamp > ago(7d)
| summarize count() by Event
| extend percentage = 100.0 * count_ / total_events
此外,您可以实现子查询的结果并使用运算符重新使用它们as
:https ://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/asoperator
例如:
T
| where Timestamp > ago(7d)
| summarize count() by Event
| as hint.materialized=true TT
| extend percentage = 100.0 * count_ / toscalar(TT | summarize sum(count_))