select td.ancestorID,gs.name,gs.wareHouseId,gs.wareHouseName,gs.orgUnitCode,gs.orgUnitName,sum(gs.amount) amount into temp from GoodsStock gs join TousseDefinition td on gs.tousseDefinitionId=td.id where td.tousseType = '消毒物品' and td.forDisplay='0' group by td.ancestorID,gs.name,gs.wareHouseId,gs.wareHouseName,gs.orgUnitCode,gs.orgUnitName; delete from GoodsStock where tousseDefinitionId in (select id from TousseDefinition td where td.tousseType = '消毒物品' and td.forDisplay='0'); insert into GoodsStock(goodstype,tousseDefinitionId,name,warehouseid,warehousename,orgunitcode,orgunitname,amount) select '器械包',t.ancestorId,t.name,t.warehouseid,t.warehousename,t.orgunitcode,t.orgunitname,t.amount from temp t; drop table temp;