select isnull(a.name,b.name) as fn, sum(a.money), sum(b.money) from tab1 a full join tab2 b on a.name=b.name group by isnull(a.name,b.name)
select a.name,sum(a.money) as money1,sum(b.money) as money2 from tab1 a,tab2 b where a.name=b.name group by a.name
select isnull(a.name,b.name) as 公司名称,isnull(a.[money],0) as 汇总申报金额,isnull(b.[money],0) as 汇总实收金额 from ( select name,sum([money]) as [money] from tab1 group by name ) as a full join ( select name,sum([money]) as [money] from tab1 group by name ) as b on a.name=b.name
victorycyz(中海) 的数据会加倍
select name sum(money) into #t1 from tab1 group by name select name sum(money) into #t2 from tab2 group by name select #t1.name,#t1.money,#t2.money from #t1 inner join #t2 on #t1.name=#t2.name drop talbe #t1 drop talbe #t2
select isnull (a.公司名称,b.公司名称) as 公司名称, isnull (a.申报金额,0) as 申报金额, insull (b.实收金额,0) as 实收金额from (select 公司名称,sun(申报金额) as 申报金额 from tab1 group by 公司名称) a full join (select 公司名称,sun(实收金额) as 实收金额 from tabb group by 公司名称) b on a.公司名称=b.公司名称
sum(a.money),
sum(b.money)
from tab1 a full join tab2 b on a.name=b.name
group by isnull(a.name,b.name)
from (
select name,sum([money]) as [money] from tab1 group by name
) as a full join
(
select name,sum([money]) as [money] from tab1 group by name
) as b
on a.name=b.name
select name sum(money) into #t2 from tab2 group by name
select #t1.name,#t1.money,#t2.money
from #t1 inner join #t2 on #t1.name=#t2.name
drop talbe #t1
drop talbe #t2
isnull (a.公司名称,b.公司名称) as 公司名称,
isnull (a.申报金额,0) as 申报金额,
insull (b.实收金额,0) as 实收金额from
(select 公司名称,sun(申报金额) as 申报金额 from tab1 group by 公司名称) a
full join
(select 公司名称,sun(实收金额) as 实收金额 from tabb group by 公司名称) b
on a.公司名称=b.公司名称