我的桌子看起来像这样:
| 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中执行此操作?
答案 0 :(得分:2)
借用Abelisto's answer,您可以在行{s}}中使用duration_day
generate_series()
生成duration_day
值的系列。该函数使用my_table
中的SELECT name, start_date + n AS date
FROM my_table, generate_series(0, duration_day - 1) AS x(n);
值到隐式table function。
<select class="form-control" name="companyinternaltier"
ng-required="true" ng-model="companyData.InternalTierId"
ng-options="item.Id as item.Name for item in lookUps.internalTier">
<option value="">- Select Internal Tier Level -</option>
答案 1 :(得分:0)
select
name,
start_date + generate_series(0, duration_day - 1)
from
your_table;