Select t.x1,t.x2,t.x3,sum(x3)
from
(
select * from a 
union
select * from b 
)as t
    group by a.x1,a.x2,a.x3

解决方案 »

  1.   

    Select c.x1,c.x2,c.x3,sum(*)
    from
    ( select * from a where...   union   select * from b where...) c
    group by c.x1,c.x2,c.x3
      

  2.   

    Select x1,x2,x3,sum(你要的字段)
    from
    (
    select * from a where...
    union
    select * from b where...
    ) c 
    group by c.x1,c.x2,c.x3
      

  3.   

    create table a(x1 int ,x2 int,x3 int)
    create table b(x1 int ,x2 int,x3 int)Select AT.x1,T.x2,T.x3,sum(x1)
    from
    (select * from a 
      union select * from b 
    ) T 
    group by T.x1,T.x2,T.x3
      

  4.   


    Select a.x1,a.x2,a.x3,sum(*)
    from
    (
    select * from a where...
    union
    select * from b where...
    )
    group by a.x1,a.x2,a.x3 WITH ROLLUP
      

  5.   

    Select a.x1,a.x2,a.x3,sum(*)
    from
    (
    select * from a where...
    union
    select * from b where...
    ) a
    group by a.x1,a.x2,a.x3
      

  6.   

    create table a(x1 int ,x2 int,x3 int)
    create table b(x1 int ,x2 int,x3 int)select x1,x2,sum(x3) as sum_x3 from
    ( select x1,x2,x3 from a
      union 
      select x1,x2,x3 from b
    )t
    group by x1,x2