1
這個post讓我開始了。使用和理解空列的pivot()
with inventory_row as
(select 1 as item_id, '2014AA' as batch_year, 'AA' as batch_code from dual union all
select 1 as item_id, '2012BB' as batch_year, 'BB' as batch_code from dual union all
select 1 as item_id, '2012CC' as batch_year, 'CC' as batch_code from dual union all
select 2 as item_id, '2012BB' as batch_year, 'BB' as batch_code from dual union all
select 3 as item_id, '2014AA' as batch_year, 'AA' as batch_code from dual
)
select * from (
select item_id,
batch_year,
batch_code
from inventory_row
where (batch_year = '2014AA' and batch_code='AA')
or
(batch_year = '2012BB' and batch_code='BB')
)
--pivot (max(item_id) for batch_year in ('2014AA' as batch_1, '2012BB' as batch_2))
預期的效果
打開本
ID BATCH_YR CODE
1 2014AA AA
1 2012BB BB
2 2012BB BB
3 2014AA AA
進入這
ITEM_ID BATCH_14 CODE BATCH_12 CODE
1 2014AA AA 2012BB BB
2 null null 2012BB BB
3 2014AA AA null null
奧拉夫:歡迎來到SO。感謝您的迴應。 – zundarz