有两个表,A(NAME,NUM1),B(NAME,NUM2),我要输出(NAME,NUM1,NUM2)用SQL语言应该怎么写?

问题描述:

有两个表,A(NAME,NUM1),B(NAME,NUM2),我要输出(NAME,NUM1,NUM2)用SQL语言应该怎么写?

select Name,Sum(Num1) Num1,Sum(Num2) Num2 From
(
select Name,Num1,0 as Num2
from A
Union All
select Name,0 as Num1,Num2
from B
) C
group by C.Name