我想寫一條SQL指令更新我的數據庫庫存產品數量與所有交付和訂單的總數相關。更新與聚合函數和選擇
UPDATE tbl_Product
SET tbl_Product.Quantity = Q.Quantity
FROM
tbl_Product
INNER JOIN
(
SELECT tbl_Order.IdProduct,
SUM(tbl_Delivery.Quantity)-SUM(tbl_Order.Quantity) AS Quantity
FROM
tbl_Order
INNER JOIN
tbl_Delivery
ON tbl_Order.IdProduct = tbl_Delivery.IdProduct
GROUP BY tbl_Order.IdProduct
) as Q
ON Q.IdProduct = tbl_Product.IdProduct;
出現語法錯誤。
你能發佈你的錯誤陳述嗎? –