码迷,mamicode.com
首页 > 数据库 > 详细

sql语句优化

时间:2018-06-29 14:16:23      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:style   update   inner   from   mount   sum   sele   更新   color   

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语句优化

标签:style   update   inner   from   mount   sum   sele   更新   color   

原文地址:https://www.cnblogs.com/blackarrow/p/9242635.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!