我现在没环境测试,你测测吧
update table2 set 采购数量=
( select sum(进货数量)
from table1 where 进货日期 >= 上月同日 and 进货日期 < today
and table1.id = table2.id )
update table2 set 采购数量=
( select sum(进货数量)
from table1 where 进货日期 >= 上月同日 and 进货日期 < today
and table1.id = table2.id )
在采购计划表table2 中应该没有 在 进货表table1
不存在的
商品id 若有 可加如下条件
where id in ( select unique id from table1 )
from table1 where 进货日期 >= 上月同日 and 进货日期 < today
group by id