我有两张表:
1-shipment_order_product(orderid,productid,quantity)
2-stock_product(productid,quantity)
在shipment_order_product表中,有多个productid
对应一个orderid
,这意味着在一个订单中我购买了多个产品。
我想根据特定的订单i更新我购买的每个productid
的stock_product
数量。
下面是我的问题:
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.
有什么解决方案吗?
发布于 2016-04-18 17:11:04
这是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
https://stackoverflow.com/questions/36700155
复制相似问题