我已在“流分析查询”下方编写了“设备离线状态”警报。如果最近5分钟内没有从设备接收到任何输入,查询就会向我发出警报。
我需要该设备的最后一个远程信息记录(最后知道的位置),但我正在获取该设备的所有数据。我尝试了LAST和TopOne,但是它们都是开窗方法。除了自定义功能,还有其他解决方案吗?
SELECT
t1.header.serialNumber as serialNumber,t1.header.make as
make,t1.header.messageTimestamp as MessageTime,'Device Offline Alert' as
alertType
INTO
[alertOutput2]
FROM
[tsfInput] t1 TIMESTAMP BY header.messageTimestamp
LEFT OUTER JOIN [tsfInput] t2 TIMESTAMP BY header.messageTimestamp
ON
t1.header.serialNumber=t2.header.serialNumber AND
t1.header.make=t2.header.make
AND DATEDIFF(minute, t1, t2) BETWEEN 1 and 5
WHERE t2.serialNumber IS NULL
样本输入
{
"header": {
"assetKey": 8910053376183227000,
"make": "CAT36",
"serialNumber": "Truck36",
"deviceType": "A5:N2",
"isPriority": false,
"isReplay": true
}
}
答案 0 :(得分:0)
我可以修复查询,但不能100%修复。从查询中删除以下行并可以正常使用后,仍然不清楚为什么它不能与TimeStamp一起使用
TIMESTAMP BY header.messageTimestamp
我有2个查询,其中1个是设备在线警报,第二个是设备离线警报
SELECT
*,'Device Online Alert' as alertType
INTO
[alertOutput]
FROM
[tsfInput]
WHERE ISFIRST(mi, 5) OVER (PARTITION BY header.serialNumber,header.make) = 1
SELECT t1.*,'Device Offline Alert' as alertType
INTO
[alertOutput2]
FROM [tsfInput] t1
LEFT OUTER JOIN [tsfInput] t2
ON t1.header.serialNumber=t2.header.serialNumber AND t1.header.make=t2.header.make
AND DATEDIFF(minute, t1, t2) BETWEEN 1 and 5
WHERE t2.header IS NULL