select distinct year, month, max(sjz), max(yjz) from
(select year, month, money as sjz, 0 as yjz from a 
union all
select  year, month, 0 as sjz, money as yjz from b)

解决方案 »

  1.   

    select t1.y,t1.m,nvl(t2.m,0),t1.mo,nvl(t2.mo,0) from 
    (select a.year as y,a.month as m,a.money as mo from a
    union
    select nvl(a.year,b.year) as y,nvl(a.month,b.month) as m,nvl(a.money,b.money) as mo from a,b where 
    a.month(+)=b.month) t1,
    (select b.year as y,b.month as m,b.money as mo from a,b where a.month=b.month) t2 where t1.m=t2.m(+)
      

  2.   

    select  decode(a.REVENUE_ITEM_NID,null,b.REVENUE_ITEM_NID,a.REVENUE_ITEM_NID),
            decode(a.year,null,b.year,a.year),
            decode(a.month,null,b.month,a.month),
            decode(a.money,null,0,a.money),
            decode(b.money,null,0,b.money)
    from ss_tmonth_revenue  a 
    full join predict_revenue_month b 
    on b.nid = a.nid and b.year = a.year and b.month = a.month;