Kusto KQL 相当于 with 子句

Kusto KQL equivalent to with clause

我正在尝试寻找 MySQL (v8) 的替代方法

我有一些使用 with 子句为某些结果设置别名的长查询。

with top5 as (
        SELECT ....
) 
SELECT .... from top5 
UNION ALL .... from top5

我正在尝试在 Kusto KQL 中找到与 with 子句等效的项。

如有任何帮助,我们将不胜感激。

我认为 let 语句是您要查找的内容:https://docs.microsoft.com/en-us/azure/kusto/query/letstatement#using-materialize-function

下面是 let 绑定到表格结果集的示例:

let Top5 = StormEvents | top 5 by StartTime;
Top5
| union StormEvents
| take 10

您还可以使用 as 运算符来命名子查询并在以后使用它,例如:

MyLogTable  
| where type == "Event"
| as T
| where Name == "Start"
| join (
    T
    | where Name == "Stop"
) on ActivityId