我有这个查询
select a.ord_no,a.item_no, a.line_no, b.from_item_no_1,b.qty_1, b.from_item_no_2,b.qty_2, b.from_item_no_3, b.qty_3,b.from_item_no_4,b.qty_4 from oeordlin_progview a
join oepiklst_sql b on a.ord_no = b.ord_no and a.line_no = b.line_seq_no
WHERE a.ord_type = 'O'
AND a.loc = '1'
AND a.picked_dt IS NULL
AND a.line_item_status = 'FRFIN'
and a.ord_no = 410672
order by a.line_no
返回此结果集
ord_no item_no line_no from_item_no_1 qty_1 from_item_no_2 qty_2 from_item_no_3 qty_3 from_item_no_4 qty_4
00410672 12167 2 1 1.0000 2 5.0000 3 9.0000 4 13.0000
00410672 10 3 10000 1.0000 2 6.0000 3 12.0000 4 3.0000
00410672 2 4 1 1.0000 2 7.0000 3 2.0000 4 2.0000
我如何为每个项目编号看起来像这样
-------item_No 12167
ord_no, item_no, line_no, 1, from_item_no_1, qty_1
ord_no, item_no, line_no, 2, from_item_no_2, qty_2
ord_no, item_no, line_no, 3, from_item_no_3, qty_3
ord_no, item_no, line_no, 4, from_item_no_4, qty_4
-------item_No 10
-------item_No 2
答案 0 :(得分:0)
我能做到这一点,但它很混乱。
select a.ord_no, a.item_no,a.line_no,1, b.from_item_no_1,b.qty_1 from oeordlin_progview a
join oepiklst_sql b on a.ord_no = b.ord_no and a.line_no = b.line_seq_no
WHERE a.ord_type = 'O'
AND a.loc = '1'
AND a.picked_dt IS NULL
AND a.line_item_status = 'FRFIN'
and a.ord_no = 410672
union all
select a.ord_no, a.item_no,a.line_no,2, b.from_item_no_2,b.qty_2 from oeordlin_progview a
join oepiklst_sql b on a.ord_no = b.ord_no and a.line_no = b.line_seq_no
WHERE a.ord_type = 'O'
AND a.loc = '1'
AND a.picked_dt IS NULL
AND a.line_item_status = 'FRFIN'
and a.ord_no = 410672
union all
select a.ord_no, a.item_no,a.line_no,3, b.from_item_no_3, b.qty_3 from oeordlin_progview a
join oepiklst_sql b on a.ord_no = b.ord_no and a.line_no = b.line_seq_no
WHERE a.ord_type = 'O'
AND a.loc = '1'
AND a.picked_dt IS NULL
AND a.line_item_status = 'FRFIN'
and a.ord_no = 410672
union all
select a.ord_no, a.item_no,a.line_no,4,b.from_item_no_4,b.qty_4 from oeordlin_progview a
join oepiklst_sql b on a.ord_no = b.ord_no and a.line_no = b.line_seq_no
WHERE a.ord_type = 'O'
AND a.loc = '1'
AND a.picked_dt IS NULL
AND a.line_item_status = 'FRFIN'
and a.ord_no = 410672
order by line_no