SQL 多表关联更新

样式:

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 多表关联更新

上一篇:MySQL 常用字段类型与对应的Java类型


下一篇:数据库tempdb的事物日志已满,原因为“ACTIVE_TRANSACTION”