合并表,同时合并部分数据
有两个表 T1 T2
T1
name count
A 3
B 5
C 3
T2
name count
A 2
B 3
D 4
得到如下表T3
name count
A 5
B 8
C 3
D 4
把两个表合并,按name分组,并把count值相加
越简单越好,谢谢
------解决方案--------------------select name, sum(count) as count
from (
select name, count
from t1
union
select name, count
) as t
group by name
------解决方案--------------------可以不需要用的union,直接用full join
Select
IsNull(A.Name, B.Name) As Name,
IsNull(A.[count], 0) + IsNull(B.[count], 0) As [count]
From
A
Full Join
B
On A.Name = B.Name