各位版大...請問有什麼方式可以達到下圖的結果...我的SQL目前如下..但是會出現錯誤訊息...x.A1:無效的ID
請版大指導..謝謝!!
select x.*,(x.A1+x.B1) as A3 from (select cod_item,type,qty,
case type
when'A1' then qty
else 0
end
"A1",
when'B1' then qty
else 0
end
"B1" from item)x
------解决方案--------------------
WITH item AS
(
SELECT 'AA' CODE_ITEM ,'A1' TYPE, 1 QTY FROM DUAL UNION
SELECT 'BB' CODE_ITEM ,'D1' TYPE, 2 QTY FROM DUAL UNION
SELECT 'CC' CODE_ITEM ,'B1' TYPE, 1 QTY FROM DUAL UNION
SELECT 'DD' CODE_ITEM ,'C1' TYPE, 1 QTY FROM DUAL
)
SELECT
CODE_ITEM
,TYPE
,QTY
,DECODE(TYPE,'A1',1,0)
,DECODE(TYPE,'B1',1,0)
,DECODE(TYPE,'A1',1,'B1',1,0)
FROM ITEM