我实际上很喜欢Andomar的解决方案(添加了自动填充Periods表的流程),但出于乐趣,这里的解决方案不需要它。
CREATE TABLE your_table (start_date date, end_date date);INSERT INTO your_table VALUES ('Jan-17-2008', 'May-20-2009');SELECt GREATEST(start_date, ('04-01-'||series.year)::date) AS year_start, LEAST(end_date, ('03-31-'||series.year + 1)::date) AS year_endFROM (SELECt start_date, end_date, generate_series( date_part('year', your_table.start_date - INTERVAL '3 months')::int, date_part('year', your_table.end_date - INTERVAL '3 months')::int) FROM your_table) AS series(start_date, end_date, year)ORDER BY start_date;


