我有2个arduino设备向我的宽带棒发送短信(湿度,温度和降雨量),我还有一个C#应用程序将文本中的数据保存到我的sql数据库,问题是如何平均输入我humidity
字段上temperature
字段间隔1分钟的两台设备rainfall
,time
和Timestamp(3)
?
这不起作用,但这是我认为它会起作用的方式。
Select AVG(humidity) as humidity WHERE time BETWEEN (LAST INPUT TIMESTAMP) interval = 1 min?
答案 0 :(得分:0)
Select AVG(humidity) as humidity WHERE time BETWEEN (LAST INPUT TIMESTAMP) AND DATE_SUB((LAST INPUT TIMESTAMP), INTERVAL 1 MINUTE)
说明:
DATE_SUB((LAST INPUT TIMESTAMP), INTERVAL 1 MINUTE)
您的当前时间戳(LAST INPUT TIMESTAMP)
将被间隔INTERVAL 1 MINUTE
根据您的评论进行修改:
执行子选择以获取最后一个时间戳,如:
SELECT AVG(humidity) as humidity
FROM table
WHERE time BETWEEN (SELECT TOP 1 timestamp FROM table ORDER by timestamp DESC)
AND DATE_SUB((SELECT TOP 1 timestamp FROM table ORDER by timestamp DESC), INTERVAL 1 MINUTE)