在开始和结束日期之间选择每个月。

时间:2022-10-18 10:19:46

Say I have a startdate = '2010/04/01' and an enddate = '2011/02/01'.

假设我有一个startdate = '2010/04/01'和一个enddate = '2011/02/01'。

How would I set up a query such that I retrieve the following table as a response:

我将如何设置一个查询,以便检索下表作为响应:

month
2010/04/01
2010/05/01
2010/06/01
2010/07/01
2010/08/01
2010/09/01
2010/10/01
2010/11/01
2010/12/01
2011/01/01
2011/02/01

Note that I'm not too fussed about the format, anything that works will do.

注意,我对格式不是太在意,任何有用的东西都可以。

1 个解决方案

#1


5  

PostgreSQL has generate_series() to make that an easy task:

PostgreSQL有generate_series(),可以轻松完成以下任务:

SELECT generate_series('2010-04-01', '2011-02-01', interval '1 month')::date

#1


5  

PostgreSQL has generate_series() to make that an easy task:

PostgreSQL有generate_series(),可以轻松完成以下任务:

SELECT generate_series('2010-04-01', '2011-02-01', interval '1 month')::date