【发布时间】:2016-06-27 08:45:29
【问题描述】:
我的表格如下所示:
| name | start_date | duration_day|
========================================
| A | 2015-01-01 | 3 |
| B | 2015-01-02 | 2 |
现在我想得到这样的输出:
| name | date |
=====================
| A | 2015-01-01 |
| A | 2015-01-02 |
| A | 2015-01-03 |
| B | 2015-01-02 |
| B | 2015-01-03 |
如何在 PostgreSQL 中做到这一点?
【问题讨论】:
-
@Bulat 不是。不是 PG,而且 PG 中也有比那个答案更好的解决方案。
-
@Patrick,感谢 Patrick 更新我的问题
-
可以在此处找到使用动态计数表的通用解决方案示例stackoverflow.com/questions/31402329/…,但对于使用 generate_series 的 PG 来说,这很整洁
-
duration_day可以是NULL还是0,这将如何影响结果?请始终提供您的 Postgres 版本。LATERAL加入是在 pg 9.3 中引入的:stackoverflow.com/a/19127999/939860
标签: sql postgresql generate-series set-returning-functions