我希望使用postgresql从开始时间戳开始每3分钟选择一次表中的数据。
31-12-2015 10:00:00
31-12-2015 10:01:00
31-12-2015 10:02:00
31-12-2015 10:03:00
31-12-2015 10:04:00
31-12-2015 10:05:00
必需输出
31-12-2015 10:00:00
31-12-2015 10:03:00
答案 0 :(得分:1)
使用样本表
CREATE TABLE tm (tme TIMESTAMP);
INSERT INTO tm
VALUES ('31-12-2015 10:00:00')
,('31-12-2015 10:01:00')
,('31-12-2015 10:02:00')
,('31-12-2015 10:03:00')
,('31-12-2015 10:04:00')
,('31-12-2015 10:05:00');
并且选择应该是
SELECT *
FROM tm
WHERE to_char(tme, 'MI')::INT IN (
SELECT *
FROM (
SELECT to_char(tme, 'MI')::INT col
FROM tm
) t
WHERE mod(col, 3) = 0
);
简化
select *
from
tm where mod(to_char(tme, 'MI')::int,3)=0
结果:
tme
-------------------
2015-12-31 10:00:00
2015-12-31 10:03:00