求和:
select sum(A) from table1 where id = '1';
select sum(B) from table2 where id = '1';
若求和值为Null,需要转换,否组会报错
通过IFNULL转换,转换格式:IFNULL(字段,0)
调整后如下:
select IFNULL(sum(A),0) from table1 where id = '1';
select IFNULL(sum(B),0) from table2 where id = '1';
相减:
select (select IFNULL(sum(A),0) from table1 where id = '1') - (select IFNULL(sum(B),0) from table2 where id = '1')