假设每一张进仓单中的货物是唯一的:insert 仓库(货物,进仓数) select 货物,0 from 进仓单 as d where 单号=1234567 and not exists( select * from 仓库 where 货物=d.货物) update c set 进仓数=进仓数-d.进仓数 from 仓库 as c inner join 进仓单 as d on c.货物=d.货物 where d.单号=1234567为什么允许“负的”进仓数?因为你只说要“还原”。如果进仓之后又被出仓,那么“还原有什么意义”等你来说明。
select 货物,0 from 进仓单 as d where 单号=1234567 and not exists(
select * from 仓库 where 货物=d.货物)
update c set 进仓数=进仓数-d.进仓数
from 仓库 as c inner join 进仓单 as d on c.货物=d.货物
where d.单号=1234567为什么允许“负的”进仓数?因为你只说要“还原”。如果进仓之后又被出仓,那么“还原有什么意义”等你来说明。