我创建了一个超表 water_meter 来存储传感器数据
它包含以下按时间戳升序排列的数据
select * from water_meter order by time_stamp;
可以看出我的数据从01 May 2020
如果我使用 time_bucket() 函数来获取每 1 天的聚合:
SELECT
time_bucket('1 days', time_stamp) as bucket,
thing_key,
avg(pulsel) as avg_pulse_l,
avg(pulseh) as avg_pulse_h
FROM
water_meter
GROUP BY thing_key, bucket;
它工作正常,我得到以下数据:
现在,如果我使用它来获取 15 天的聚合,我会得到意想不到的结果,其中显示了 的开始时间段17 April 2020
,而表中没有数据
SELECT
time_bucket('15 days', time_stamp) as bucket,
thing_key,
avg(pulsel) as avg_pulse_l,
avg(pulseh) as avg_pulse_h
FROM
water_meter
GROUP BY thing_key, bucket;