假设我有一个表C_OrderLine
,并且有三个以下带有存储值的字段;
c_orderline_id = 1000
m_product_id = 2000
qty = 5
现在我希望sql查询获得m_product_id
(2000)与qty
(5)的值一样多的行。查询结果应如下:
2000
2000
2000
2000
2000
答案 0 :(得分:1)
你在这里:
select inner_query.m_product_id from
(
select
m_product_id,
generate_series(1, qty)
from C_OrderLine
) as inner_query
答案 1 :(得分:0)
PostgreSQL 9.3架构设置:
查询1 :
with conf(base, cnt) as (
values (20000,5)
)
select conf.base
from conf
join generate_series(1,cnt) on true
<强> Results 强>:
| base |
|-------|
| 20000 |
| 20000 |
| 20000 |
| 20000 |
| 20000 |