我正在嘗試在 KQL 上撰寫一個帶有變數的查詢。這是它的第一部分:

我想在其他查詢中使用它來添加一個列,其中包含每個事件在總數中的百分比。換句話說,百分比 = EventNumber / totalEvents。
這是我的第二個查詢:

但是當我嘗試組合查詢時出現錯誤。你能幫我解決這個問題嗎?

uj5u.com熱心網友回復:
您可以嘗試使用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_))
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/339905.html
標籤:变量 天蓝色数据浏览器 千斤顶 kusto-explorer
