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语句优化的主要内容,如果未能解决你的问题,请参考以下文章

Microsoft SQL Server 代码片段收集

SQL优化之语句优化

Oracle游标sql语句代码块的优化

SQL语句常见优化十大案例

MYBATIS05_ifwherechoosewhentrimsetforEach标签sql片段

代码优化之SQL优化