我正在尝试更新" Price"名为" Products"在此示例中使用" Quantity"来自另一个名为" OrderDetails的表的字段。我使用t作为临时表来存储我的OrderDetails的查询结果,然后INNER JOIN这两个表(p和t)。我仍然得到错误。我验证了查询片(SELECT ...... GROUP BY ProductID)的工作原理。它是引发错误的UPDATE。任何想法?
UPDATE p
SET Price = t.sumQuan
FROM Products AS p
INNER JOIN
(
SELECT ProductID, SUM(Quantity) sumQuan
FROM OrderDetails
GROUP BY ProductID
) t
ON t.ProductID = p.ProductID;
答案 0 :(得分:1)
可能只是Access与其他RDBMS的语法差异?
UPDATE products
INNER JOIN (SELECT ProductID, SUM(Quantity) sumQuan
FROM OrderDetails
GROUP BY ProductID
) t
ON t.ProductID = p.ProductID;
SET Price = t.sumQuan