两个表数据相加!
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