结果1数据 No data     结果2数据 No data
         1  15                1   5
         2  20                2   5
         3  25                3   5
----------------------------------------
最后想要合并的结果是No data
                  1   20
                  2   25
                  3   30
就是No不变,将两个结果的data相加,得出一个新的结果

解决方案 »

  1.   

    select no,sum(data) as data
    from (
    select * from A
    union all
    select * from B
    ) t
    group by no
      

  2.   

    select no,sum(data) as data from (
    select no,data from 表a
    union all
    select no,data from 表 b)t
    group by no
      

  3.   

    select a.no,a.data    +b.data    
    from 结果1 a,结果2 b
    where a.no=b.no
      

  4.   

    select no,sum(data) as data from (
     select no,data from 表a 
    union all
     select no,data from 表 b
    )t group by no
    order by no
      

  5.   

    SELECT COL1,SUM(COL2)COL2 FROM
    (
    SELECT COL1,COL2 FROM TA
    UNION ALL
    SELECT COL1,COL2 FROM TB
    )
    T
    GROUP BY COL2
      

  6.   


    select No ,sum(data)
    from(
    select No ,data   
    from 表1
    union all
    select No  ,data   
     from 表2)a
    group by No