select * from t1
union
select * from t2
union 
select * from t3

解决方案 »

  1.   

    select f1,sum(f2) from (select * from t1
    union all
    select * from t2
    union all
    select * from t3
    ) a group by f1
      

  2.   

    declare @t1 table(f1 varchar(10),f2 int)
    insert @t1 values('A',10)
    insert @t1 values('B',20)
    insert @t1 values('C',30)declare @t2 table(f1 varchar(10),f2 int)
    insert @t2 values('A',10)
    insert @t2 values('B',20)
    insert @t2 values('C',30)
    insert @t2 values('D',40)declare @t3 table(f1 varchar(10),f2 int)
    insert @t3 values('A',10)
    insert @t3 values('B',20)
    insert @t3 values('E',30)
    insert @t3 values('F',40)select f1,sum(f2) from (
    select * from @t1
    union all
    select * from @t2
    union all
    select * from @t3
    ) c group by f1