首页 > 数据库技术 > 详细

SQL 多表关联更新

时间:2020-06-02 10:56:05      阅读:48      评论:0      收藏:0      [点我收藏+]

样式:

UPDATE t1 set t1.oi_PayAmount=t2.payAmount
from 表A t1
join 表B t2 on t1.oi_id=t2.id
where t1.oi_Status=44

 

 

示例:


UPDATE t1 set t1.oi_PayAmount=t2.payAmount
from Order t1
join (select id,payAmount
from(select oi_Id as id,ISNULL(sum(po_ReceiveExpense),0) as payAmount
from Order
left join Payment on po_OrderId=oi_OrderNo
where oi_Status=44
group by oi_Id,oi_Price
)a)t2 on t1.oi_id=t2.id where t1.oi_Status=44

SQL 多表关联更新

原文:https://www.cnblogs.com/Bingo1363136101/p/13029317.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!