当输入为日期 (2014-01-01
) 时,我有以下查询生成给定年份的月份列表:
SELECT to_char(dd, 'Month')
FROM generate_series(CAST('2014-01-01' AS DATE), date_trunc('month', now()), '1 month') as dd;
to_char
-----------
January
February
(2 rows)
现在,我只需要传递 2014
而不是 2014-01-01
并获得相同的结果。
最佳答案
SELECT distinct to_char(dd, 'Month') FROM generate_series(to_date('2013', 'YYYY') , date_trunc('month', now()), '1 month') as dd;
关于sql - 使用 generate_series 填充 PostgreSQL 中给定年份的月份列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21933364/