我有以下代码生成订单号和值的列表...
SELECT
d.`OrderNo`,
SUM(v.`UnitPrice`)
FROM tblverification v
LEFT JOIN tblorderdetailsafter d ON v.`VMainID` = d.`MainID`
GROUP BY d.`OrderNo`;
我需要更新一个名为
matcontctsafter
的表,该表具有一个OrderNo
字段,并且当前空白的InvoiceAmount
列需要相对的SUM(v.UnitPrice)
。有人可以帮我构造
UPDATE
子句吗? 最佳答案
UPDATE matcontctsafter m
INNER JOIN (
SELECT
d.`OrderNo`,
SUM(v.`UnitPrice`) InvoiceAmount
FROM tblverification v
LEFT JOIN tblorderdetailsafter d ON v.`VMainID` = d.`MainID`
GROUP BY d.`OrderNo`
) sq ON m.OrderNo = sq.OrderNo
SET m.InvoiceAmount = sq.InvoiceAmount;