使用SELECT SQL的结果更新表

时间:2016-07-10 22:31:06

标签: sql ms-access

我遇到了将这些问题拼凑在一起的问题。你们能帮助我填补空白吗?我试图把它拼凑起来,以便其他例子在这里,但我想我完全错过了一些东西?我想我需要处理我的SQL,但我希望从该表中已有的值中减去连接中的总和函数。

UPDATE [30 on hand].IVQTY001
SET [30 on hand].IVQTY001 = 
SELECT [30 on hand].Expr1 AS [Item#],
[30 on hand].IVQTY001 AS [001 OH],
Sum(dbo_ITEMS.QUANTO) AS [Order QTY],
FROM dbo_ITEMS INNER JOIN [30 on hand] ON dbo_ITEMS.ITEM = [30 on hand].Expr1
WHERE ((dbo_ITEMS.ORDERNO) Between X AND Y
GROUP BY [30 on hand].Expr1, [30 on hand].IVQTY001;

1 个答案:

答案 0 :(得分:0)

子查询需要在括号中。我不是100%确定您的查询意图是什么,但我认为它可能是:

UPDATE [30 on hand]
    SET [30 on hand].IVQTY001 = (SELECT Sum(dbo_ITEMS.QUANTO) AS [Order QTY],
                                 FROM dbo_ITEMS 
                                 WHERE dbo_ITEMS.ITEM = [30 on hand].Expr1 AND
                                       dbo_ITEMS.ORDERNO Between X AND Y
                                );