类似这样,假设入库表和出库表有如下相同主键
A,B,C。。。number1,number2。。。字段表示数量字段
先删除库存表
或是先备份再删除,建议先备份
再执行如下sql
select aa.A,aa.B,aa.C,...,(aa.number1-bb.number1) as number1,
(aa.number2-bb.number2) as number2,...from(
select A,B,C,..,sum(number1) as number1,sum(number2) as number2,...from 入库表)aa left join (select A,B,C,..,sum(number1) as number1,sum(number2) as number2,...from 出库表) bb on aa.A=bb.A and
aa.B=bb.B and aa.C=bb.C ....