如何在 postgresql 中生成直到当年的动态年份列表?
How to generate dynamic year list till current year in postgresql?
我想使用 PostgreSQL 为我的 BIRT 报告数据集查询年份列表。
我想要从 2012 年到当年(现在是 2018 年)的年份列表,所以我需要的输出应该是这样的:
2012
2013
2014
2015
2016
2017
2018
像:
t=> select generate_series(2012,extract(year from now())::int);
generate_series
-----------------
2012
2013
2014
2015
2016
2017
2018
(7 rows)
应该做
我想使用 PostgreSQL 为我的 BIRT 报告数据集查询年份列表。
我想要从 2012 年到当年(现在是 2018 年)的年份列表,所以我需要的输出应该是这样的:
2012
2013
2014
2015
2016
2017
2018
像:
t=> select generate_series(2012,extract(year from now())::int);
generate_series
-----------------
2012
2013
2014
2015
2016
2017
2018
(7 rows)
应该做