【发布时间】:2019-01-06 15:38:31
【问题描述】:
我编写了一个查询,它将从名为allotment 的表中的现有周期生成子周期:
select a.product_id,
daterange((lower(a.allotment_period) + concat(n.i - 1, ' days')::interval)::date,
(upper(a.allotment_period) + concat(n.i, ' days')::interval)::date, '[]')
from test.allotment as a
cross join(select * from generate_series(1, a.period_length)) as n(i)
where a.id = 2
我收到了这个错误:
ERROR: invalid reference to FROM-clause entry for table "a" LINE 5: cross `join(select * from generate_series(1, a.period_length)... ^ HINT: There is an entry for table "a", but it cannot be referenced from this part of the query. SQL state: 42P01 Character: 250`
我发现了一个类似的问题SQL joins, “there is an entry for table but it cannot be referenced”,但它并没有解决我的问题。有人有解决这个问题的办法吗?
【问题讨论】:
标签: sql postgresql