日期:2014-05-17 浏览次数:20822 次
with a as( select 2 id, 900 value from dual union all select 3 id, 1000 value from dual union all select 5 id, 860 value from dual union all select 4 id, 1780 value from dual union all select 8 id, 808 value from dual), b as( select 2 id, 900 value from dual union all select 3 id, 1000 value from dual union all select 7 id, 860 value from dual union all select 1 id, 1780 value from dual union all select 8 id, 808 value from dual union all select 10 id, 1000 value from dual) SELECT nvl(b.id, a.id) id, CASE WHEN a.id IS NOT NULL AND b.id IS NOT NULL THEN b.value - a.value WHEN a.id IS NOT NULL THEN -a.value ELSE b.value END VALUE FROM a FULL OUTER JOIN b ON a.id = b.id;