[英]SQL query to calculate average data
I have a SQLite DB and I want to compress some data from a temperature readings. 我有一个SQLite数据库,我想从温度读数中压缩一些数据。 The readings are recorded every minute.
每分钟记录一次读数。 I have no problem to calculate this on a daily base with
我没有问题可以每天计算
"SELECT date(Time_T), AVG(reading) AS reading_avg, MIN(reading) AS reading_min, MAX(reading) AS reading_max FROM readings WHERE (Zeitpunkt_T > '2016-02-20') GROUP BY (SELECT date(Time_T))"
That works pretty fine and gives me daily averages together with min & max. 效果很好,并为我提供了每日平均值和最小值和最大值。 But this compression is too much.
但是这种压缩太多了。 I would like to have values per hour.
我希望每小时都有值。 How can I calculate this ?
我该如何计算?
I would like to have values per hour
我想要每小时的价值
It looks like you would like to group by the hour. 您似乎想按小时分组。
To get hours in sqlite, use the strftime
function and pass in %H
as the formatter. 要使用sqlite表示小时,请使用
strftime
函数并将%H
作为格式程序传递。
SELECT date(Time_T), AVG(reading) AS reading_avg, MIN(reading) AS reading_min,
MAX(reading) AS reading_max
FROM readings
WHERE (Zeitpunkt_T > '2016-02-20')
GROUP BY strftime("%H", date);
https://www.sqlite.org/lang_datefunc.html https://www.sqlite.org/lang_datefunc.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.