日期:2014-05-17 浏览次数:20760 次
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