简体   繁体   中英

Select each month between a start and end date

Say I have a startdate = '2010/04/01' and an 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.

PostgreSQL有generate_series()使这项任务变得简单:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM