日期:2014-05-18  浏览次数:20569 次

两个表数据相加!
select   vendorid,sum(totalamt)   as   'totalamt '   from   [RECIEVED]   group   by   vendorid

union   all

select   vendorid,   sum(totalpay)   as   'totalamt '   from   [cashpay]   group   by   vendorid
我想要的结果是如果vendorid想同的时候,totalamt相加。。。

------解决方案--------------------

select vendorid,sum(totalamt) as 'totalamt ' from
(select vendorid,totalamt from [RECIEVED] group by vendorid
union all
select vendorid, totalpay from [cashpay] group by vendorid)
as tt
group by tt.vendorid