prev()

返回指定行中特定列的值。 指定的行与序列化行集中的当前行存在指定的偏移量。

语法

prev(column, [ offset ], [ default_value ] )

详细了解语法约定

参数

客户 类型​​ 必需 说明
column string 要从中获取值的列。
offset int 行中向后的偏移量。 默认值为 1。
default_value 标量 (scalar) 当前面没有可从中获取值的行时要使用的默认值。 默认值为 null

示例

基于相邻行之间的比较筛选数据

以下查询返回显示调用 sensor-9 之间的间隔超过四分之一秒的行。

TransformedSensorsData
| where SensorName == 'sensor-9'
| sort by Timestamp asc
| extend timeDiffInMilliseconds = datetime_diff('millisecond', Timestamp, prev(Timestamp, 1))
| where timeDiffInMilliseconds > 250

输出

时间戳 SensorName PublisherId MachineId timeDiff
2022-04-13T00:58:53.048506Z sensor-9 0.39217481975439894 fdbd39ab-82ac-4ca0-99ed-2f83daf3f9bb M100 251
2022-04-13T01:07:09.63713Z sensor-9 0.46645392778288297 e3ed081e-501b-4d59-8e60-8524633d9131 M100 313
2022-04-13T01:07:10.858267Z sensor-9 0.693091598493419 278ca033-2b5e-4f2c-b493-00319b275aea M100 254
2022-04-13T01:07:11.203834Z sensor-9 0.52415808840249778 4ea27181-392d-4947-b811-ad5af02a54bb M100 331
2022-04-13T01:07:14.431908Z sensor-9 0.35430645405452 0af415c2-59dc-4a50-89c3-9a18ae5d621f M100 268
... ... ... ... ... ...

基于相邻行之间的比较执行聚合

以下查询计算调用 sensor-9 之间的平均时间差(以毫秒为单位)。

TransformedSensorsData
| where SensorName == 'sensor-9'
| sort by Timestamp asc
| extend timeDiffInMilliseconds = datetime_diff('millisecond', Timestamp, prev(Timestamp, 1))
| summarize avg(timeDiffInMilliseconds)

输出

avg_timeDiffInMilliseconds
30.726900061254298

使用上一行中的数据扩展行

在以下查询中,作为使用 serialize 运算符完成的序列化的一部分,一个新列 previous_session_type 将被添加,其中包含上一行中的数据。 由于在第一个会话之前没有会话,因此第一行中的列为空。

ConferenceSessions
| where conference == 'Build 2019'
| serialize previous_session_type = prev(session_type)
| project time_and_duration, session_title, session_type, previous_session_type

输出

time_and_duration session_title session_type previous_session_type
Mon, May 6, 8:30-10:00 am Vision Keynote - Satya Nadella Keynote
Mon, May 6, 1:20-1:40 pm Azure Data Explorer: Advanced Time Series analysis Expo Session Keynote
Mon, May 6, 2:00-3:00 pm Azure's Data Platform - Powering Modern Applications and Cloud Scale Analytics at Petabyte Scale Breakout Expo Session
Mon, May 6, 4:00-4:20 pm How BASF is using Azure Data Services Expo Session Breakout
Mon, May 6, 6:50 - 7:10 pm Azure Data Explorer: Operationalize your ML models Expo Session Expo Session
... ... ... ...