【发布时间】:2022-01-16 20:01:55
【问题描述】:
我正在使用以下查询生成一个时间序列。
SELECT * from (
select * from generate_series(
date_trunc('hour', '2021-11-13 10:01:38'::timestamp),
'2021-12-13 10:01:38'::timestamp,
concat(480, ' minutes')::interval) as t(time_ent)) as t
where t."time_ent" between '2021-11-13 10:01:38'::timestamp and '2021-12-13 10:01:38'::timestamp
它会给我如下输出。
2021-11-13 18:00:00.000
2021-11-14 02:00:00.000
2021-11-14 10:00:00.000
2021-11-14 18:00:00.000
2021-11-15 02:00:00.000
但我需要类似的输出。
2021-11-13 16:00:00.000
2021-11-14 00:00:00.000
2021-11-14 08:00:00.000
2021-11-14 16:00:00.000
2021-11-15 00:00:00.000
目前,时间序列小时数取决于我通过的时间戳。在上面它给了我像02,10,18这样的小时......但我想要像00,08,16这样的小时......小时不应该取决于我通过查询的时间。我尝试了很多东西,但都没有成功。
【问题讨论】:
标签: sql postgresql