我有两张桌子:
1-shipment_order_product(orderid,productid,quantity)
2-stock_product(productid,quantity)
在shipment_order_product表中,有一个productid
对一个orderid
,这意味着我会在一个订单中购买多个产品。
我想针对特定订单更新每次stock_product
次购买的productid
数量。
这是我的问题:
update product
SET NoOfItems= (select sum(b.Quantity)
from product as a,shippment_order_product as b
where a.Product_ID=b.Product_ID
group by a.Product_ID,b.Product_ID)
这给出了错误:
Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
任何解决方案?
答案 0 :(得分:0)
这是mssql - 你标记为多个
update p
SET p.NoOfItems = sum(s.Quantity)
from product as p
join shippment_order_product as s
on p.Product_ID = s.Product_ID
group by p.Product_ID