select    a.sxh,sum(decode(a.sz,'01',a.se,0))  as  test1,sum(decode(a.sz,'02',a.se,0))  as  test2 
   from  (  
       select  sxh,nsrmc,sz,se  from  GG    
       union all 
       select  id  as  sxh,nsrmc,sz,se  from  YY  
       )  a  
   group  by  a.sxh;