用两段SQL
union all拼接
在进行字段的减
------------------参考
select sum(a1) as a1,sum(a2) as a2,sum(b1) as b1,sum(b2) as b2
from (
select A as a1,B as b1,null as a2,null as b2
from tb
where 序号=1
union all
select null as a1,null as b1,A as a2,B as b2
from tb
where 序号=2)