每行是一秒钟(时间戳增加一秒钟) 我想计算每分钟tel1和tel2的平均值。 你能帮忙吗?
CREATE TABLE "plik3" (
"timestamp" REAL,
"tel1" REAL,
"tel2" REAL
);
1577833200.0 0.0 0.0
1577833201.0 0.0 0.0
1577833202.0 0.4000317 0.0
1577833203.0 0.80006206 0.80006146
1577833204.0 0.0 0.40002593
1577833205.0 0.400032 0.0
1577833206.0 0.800055 0.400024
1577833207.0 0.0 1.2000787
1577833208.0 0.40002337 0.8000576
1577833209.0 0.0 0.40002495
1577833210.0 0.0 0.0
1577833211.0 0.4000275 0.0
1577833212.0 0.400032 0.40003648
1577833213.0 0.0 1.2000787
1577833214.0 0.0 0.40003487
1577833215.0 0.8000595 0.0
1577833216.0 0.40002593 0.40003297
基地很大。 13,046,098行
答案 0 :(得分:1)
您可以为此使用算术和聚合:
select
cast(timestamp as int) / 60 * 60 timestamp_minute,
avg(tel1) avg_tel1,
avg(tel2) avg_tel2
from plik3
group by cast(timestamp as int) / 60 * 60
表达式cast(timestamp as int) / 60 * 60
将Unix时间戳取整为分钟。
如果您想将(四舍五入的)时间戳显示为日期时间,则可以在此顶部使用datetime()
:
select
datetime(cast(timestamp as int) / 60 * 60, 'unixepoch') date_minute,
avg(tel1) avg_tel1,
avg(tel2) avg_tel2
from plik3
group by datetime(cast(timestamp as int) / 60 * 60, 'unixepoch')
答案 1 :(得分:0)
您可以使用此策略。
1577833200.0
((1577833200.0 - 1577833200.0) /60) = 0
((1577833201.0 - 1577833200.0) /60) = 0
((1577833202.0 - 1577833200.0) /60) = 0
...
...
((1577833261.0 - 1577833200.0) /60) = 1
对于在同一minute
中发生的并发记录,此计算将输出相同的值。
minute
值分组的查询select minute, avg(tel1) as avg_tel1, avg(tel2) as avg_tel2 from
(select ((`timestamp` - 1577833200.0) / 60) as minute, tel1, tel2 from plik3 as temp)
group by minute;