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) where 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);