我有两张表Product
和ProductInventory
。我创建了一个FULL Join并创建了一个查询,它为我提供了Makeflag
所有数量已经变为零的产品。
如何操作输出,以便我可以将所有数量已变为0的产品的Makeflag
值更改为1?
下面的查询实际上影响了Makeflag
的所有值,而不仅仅是数量已经为零的产品。
我做错了什么......请帮忙!
Use AdventureWorks2008R2
Select
Quantity, MakeFlag
from Production.ProductInventory
FULL Join AdventureWorks2008R2.Production.Product
ON ProductInventory.ProductID = Product.ProductID where Quantity = 0
update AdventureWorks2008R2.Production.Product set MakeFlag = 1
答案 0 :(得分:1)
这应该可以解决问题
update AdventureWorks2008R2.Production.Product set MakeFlag = 1
WHERE ProductID IN (
SELECT ProductID FROM from Production.ProductInventory where Quantity = 0
)
答案 1 :(得分:0)
UPDATE AdventureWorks2008R2.Production.Product SET MakeFlag = 1
WHERE AdventureWorks2008R2.Production.Product.ProductId IN
(SELECT Product.ProductID from Production.ProductInventory FULL Join AdventureWorks2008R2.Production.Product ON ProductInventory.ProductID = Product.ProductID where Quantity = 0)