update TousseInstance set returnGoodsItem_ID=(select max(returnGoodsItem_ID) from TousseInstance t where comboTousseInstanceId=TousseInstance.id)
where returnGoodsItem_ID is null and exists (
select 1 from TousseInstance t where t.comboTousseInstanceId=TousseInstance.id and t.returnGoodsItem_ID is not null
);
update TousseInstance set price=(
select td.price from TousseDefinition td where id=TousseInstance.tousseDefinition_id
),
 discountPrice=(
select td.discountPrice from TousseDefinition td where id=TousseInstance.tousseDefinition_id
),
 fluctuationPrice=(
select td.price from TousseDefinition td where id=TousseInstance.tousseDefinition_id
)
where comboTousseInstanceId is not null and price<>(
select td.price from TousseDefinition td where id=TousseInstance.tousseDefinition_id
) and not exists (
select 1 from Sterilizer s join sterilizationRecord sr on sr.sterilizer_id=s.id  where rapidFurnace='是' and sr.id=TousseInstance.id
);
update InvoiceItem set settlementPrice=(
select sum(price) from TousseInstance ti where ti.invoice_id=InvoiceItem.invoice_id and ti.tousseDefinition_id=InvoiceItem.tousseDefinitionId and ti.comboTousseInstanceId is not null
), settlementDiscountPrice =(
select sum(settlementDiscountPrice ) from TousseInstance ti where ti.invoice_id=InvoiceItem.invoice_id and ti.tousseDefinition_id=InvoiceItem.tousseDefinitionId and ti.comboTousseInstanceId is not null
)
where settlementPrice<>(
select sum(price) from TousseInstance ti where ti.invoice_id=InvoiceItem.invoice_id and ti.tousseDefinition_id=InvoiceItem.tousseDefinitionId and ti.comboTousseInstanceId is not null
)
and exists (
select 1 from TousseInstance ti where ti.invoice_id=InvoiceItem.invoice_id and ti.tousseDefinition_id=InvoiceItem.tousseDefinitionId and ti.comboTousseInstanceId is not null
);
update Invoice set totalPrice=(
select sum(settlementPrice) from InvoiceItem where invoice_id=Invoice.id
)
where totalPrice<>(
select sum(settlementPrice) from InvoiceItem where invoice_id=Invoice.id
);