gpt4 book ai didi

Azure 流分析 : remove duplicates while aggregating

转载 作者:行者123 更新时间:2023-12-02 07:07:16 25 4
gpt4 key购买 nike

我正在开发一个温度和压力传感器系统,我的数据通过流分析作业流动。现在,由于未收到确认以及各种其他原因,可能会发送重复的消息。所以我的数据可能是以下格式:-

DeviceID    TimeStamp    MeasurementName     Value

1 1 temperature 50
1 1 temperature 50
1 2 temperature 60

请注意,第二条记录与第一条记录重复,因为 DeviceId、Timestamp 和MeasurementName 相同。我希望在流分析作业中对这些数据采取平均超过 5 分钟的滚动窗口。所以我有这个查询

SELECT
AVG(Value)
FROM
SensorData
GROUP BY
DeviceId,
MeasurementName,
TumblingWindow(minute, 5)

此查询预计会在 5 分钟内为我提供每个设备的温度和压力值的平均测量值。在计算平均值时,我需要消除重复项。实际平均值为 (50+60)/2 = 55。但是我这个查询的平均值是 (50+50+60)/3 = 53.33

如何调整此查询以获得正确的输出?

提前致谢。

最佳答案

根据Query Language Elements在ASA中,ASA似乎不直接支持distinct。但是,您可能会发现它可以与 here 中的 COUNT 一起使用。 .

所以,也许你可以引用我的下面的sql来获取没有重复数据的平均值。

with temp as
(
select count(distinct DeviceID) AS device,
count(distinct TimeStamp) AS time,
count(distinct MeasurementName) AS name,
Value as v
from jsoninput
group by Value,TumblingWindow(minute, 5)
)
select avg(v) from temp
group by TumblingWindow(minute, 5)

输出示例数据:

enter image description here

关于Azure 流分析 : remove duplicates while aggregating,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53790519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com