我想做一个动态查询,它总是需要间隔 todays_date 和 todays_date - 30
SELECT day::date
FROM generate_series('2014-08-01'::date, '2014-09-14'::date, interval '1 week') day
但是使用当前日期,就像这样
SELECT day::date
FROM generate_series(CURRENT_DATE, CURRENT_DATE - 30, interval '1 week') day
答案 0 :(得分:1)
你几乎是对的。试试这个(增量系列):
SELECT day::date
FROM generate_series(CURRENT_DATE - interval '30 days', CURRENT_DATE, interval '1 week') day
或者如果你真的想倒退:
SELECT day::date
FROM generate_series(CURRENT_DATE, CURRENT_DATE - interval '30 days', -interval '1 week') day