原始数据:
ID      A       B
1      NULL     4
2      5       NULL
3      2       NULL
3      NULL     3
转变后的效果:
ID      A       B
1      NULL     4
2      5       NULL
3      2        3也就是把3的两条记录合并...我该怎么处理,请高手指教,谢谢了...

解决方案 »

  1.   

    select table.id,sum(A),sum(B) from table group by table.id
      

  2.   

    要是3有三条是怎么合并?
    3      2       NULL
    3      NULL     3
    3      3        3
      

  3.   

    试试看~~~SQL> select tt.ID,max(tt.A),max(tt.B)
      2    from (
      3          select 1 as ID,NULL as A,4 as B from dual
      4          union all
      5          select 2 as ID,5 as A,NULL as B from dual
      6          union all
      7          select 3 as ID,2 as A,NULL as B from dual
      8          union all
      9          select 3 as ID,NULL as A,3 as B from dual
     10         )tt
     11   group by tt.ID
     12   order by tt.ID;==================result====================        ID  MAX(TT.A)  MAX(TT.B)
    ---------- ---------- ----------
             1                     4
             2          5 
             3          2          3