Mysql联合表更新
Mysql联合表更新示例如下所示:
UPDATE purchase_un_invoice t1
INNER JOIN (
SELECT
sum( t4.tax_amount ) sumAmount,
t4.un_invoice_id
FROM
purchase_un_invoice_detail t4
INNER JOIN purchase_un_invoice t5 ON t5.id = t4.un_invoice_id
AND t5.tenant_id = 2139
AND t4.is_delete = 1
AND t5.is_delete = 1
GROUP BY
t4.un_invoice_id
) t2 ON t1.id = t2.un_invoice_id
SET t1.tax_amount = t2.sumAmount
WHERE
t1.tenant_id = 2139
AND t1.biz_type = 1
AND t1.is_delete = 1
郭慕荣博客园