sql语句优化
Posted blackarrow
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql语句优化相关的知识,希望对你有一定的参考价值。
1、批量更新数据
UPDATE s_payablebill SP SET SP.AdjustAmount = (SELECT SUM(SA.Amount) FROM s_payablebill_adjust SA WHERE SA.PayableBillId = SP.PayableBillId) WHERE SP.PayableBillId IN (SELECT PayableBillId FROM s_payablebill_adjust GROUP BY PayableBillId)
=》
UPDATE s_payablebill SP INNER JOIN (SELECT PayableBillId, SUM(Amount) AdjustAmount FROM s_payablebill_adjust GROUP BY PayableBillId) SA ON SP.PayableBillId = SA.PayableBillId SET SP.AdjustAmount = SA.AdjustAmount
以上是关于sql语句优化的主要内容,如果未能解决你的问题,请参考以下文章