SQL 在 KQL 中的领先等效项



我正在努力实现类似SQL在KQL中的领先地位。SQL中的查询如下所示-

Select lead(changedBy,1,null) Over (partition by incidentId order by historyId) nextChangedBy
from IncidentHistory IH, Incidents I
where I.IncidentId = IH.IncidentId
and I.UpdatedDate > trunc(sysdate) -30;

有人能告诉我如何在Kusto查询语言中实现同样的功能吗?我在KQL中没有看到任何引导函数。

至少在这一点上,在windows函数的这一领域,KQL比SQL更重要
我们需要对数据进行分区并排序,然后我们可以使用next((,这与SQL lead((等效。

p.S.
请注意,在SQL中不需要lead(changedBy,1,null)的详细语法
1&null是默认值,lead(changedBy)就足够了
话虽如此,如果需要,KQL确实有一个等效的语法。

let Incidents = datatable(incidentId:int, UpdatedDate:datetime)
[
1 ,datetime(2022-09-15 01:02:03)
,2 ,datetime(2022-10-01 04:05:06)
,3 ,datetime(2022-10-07 07:08:09)
];
let IncidentHistory = datatable(incidentId:int, historyId:int, changedBy:string)
[
1 , 10 , "CB1"
,2 , 20 , "CB2"
,2 , 50 , "CB3"
,2 , 60 , "CB4"
,2 , 80 , "CB5"
,3 , 30 , "CB6"
,3 , 40 , "CB7"
,3 , 70 , "CB8"
];
Incidents
| where UpdatedDate > startofday(ago(30d))
| join kind=inner IncidentHistory on incidentId
| partition hint.strategy=native by incidentId
(
order by historyId asc
| extend nextChangedBy = next(changedBy)
)
历史IdCB7CB8CB3CB4CB5
incidentId更新日期incidentId1更改日期
32022-10-07T07:08:09Z330CB6
32022-10-07T07:08:09Z3CB7CB8
32022-10-07T07:08:09Z370
22022-10-01T04:05:06Z220CB2
22022-10-01T04:05:06Z250CB3CB4
22022-10-01T04:05:06Z260
22022-10-01T04:05:06Z280CB5

最新更新