update TousseItem set materialAmount=(select sum(mi.count) amount from TousseItem ti inner join TousseDefinition td  on td.id = ti.tousseDefinitionId inner join MaterialInstance mi on mi.tousse_id = td.id where TousseItem.id=ti.id);
update RecyclingItem set materialAmount=(select sum(mi.count) amount from RecyclingItem ri inner join TousseDefinition td  on td.id = ri.tousseDefinitionId inner join MaterialInstance mi on mi.tousse_id = td.id where RecyclingItem.id=ri.id);
update ClassifiedItem set materialAmount=(select sum(mi.count) amount from ClassifiedItem ci inner join TousseDefinition td  on td.id = ci.toussedefinition_id inner join MaterialInstance mi on mi.tousse_id = td.id where ClassifiedItem.id=ci.id);
update PackingRecord set materialAmount=(select sum(mi.count) amount from PackingRecord pr inner join TousseDefinition td  on td.id = pr.tousseDefinitionId inner join MaterialInstance mi on mi.tousse_id = td.id where PackingRecord.id=pr.id);
update TousseInstance set materialAmount=(select sum(mi.count) amount from TousseInstance ti inner join TousseDefinition td  on td.id = ti.toussedefinition_id inner join MaterialInstance mi on mi.tousse_id = td.id where TousseInstance.id=ti.id);
update InvoiceItem set materialAmount=(select sum(mi.count) amount from InvoiceItem ii inner join TousseDefinition td  on td.id = ii.tousseDefinitionId inner join MaterialInstance mi on mi.tousse_id = td.id where InvoiceItem.id=ii.id);
update ReturnGoodsItem set materialAmountAtThatTime=(select sum(mi.count) amount from ReturnGoodsItem ri inner join TousseDefinition td  on td.id = ri.toussedefinition_id inner join MaterialInstance mi on mi.tousse_id = td.id where ReturnGoodsItem.id=ri.id);
update TousseDefinition set materialAmount=(select sum(mi.count) amount from MaterialInstance mi where mi.tousse_id = TousseDefinition.id);