select A,sum(B) from 
(
select A,B from test1
union all
select A,B from test2
union all
select A,-B from test3
union all
select A,-B from test4
) tem group by A