日期:2014-05-16 浏览次数:20958 次
with t1 as ( select 100 c1,200 c2,300 c3,600 c4,800 c5 from dual union all select 100 c1,200 c2,300 c3,200 c4,700 c5 from dual ) select case when c5-c4-c3-c2 <= 0 then c1 else decode(sign(c1+c2+c3+c4-c5),1,c1+c2+c3+c4-c5,0) end c1, case when c5-c4-c3 <= 0 then c2 else decode(sign(c2+c3+c4-c5),1,c2+c3+c4-c5,0) end c2, case when c5-c4 <= 0 then c3 else decode(sign(c3+c4-c5),1,c3+c4-c5,0) end c3, case when c5-c4 <= 0 then c4 else decode(sign(c4-c5),1,c4-c5,0) end c4, case when c5-c4-c3-c2-c1 <= 0 then 0 else decode(sign(c5-c4-c3-c2-c1),1,c5-c4-c3-c2-c1,0) end c5 from t1 c1 c2 c3 c4 c5 ----------------------------------------------- 1 100 200 100 0 0 2 100 0 0 0 0