0

我有两张桌子ProductProductInventory. 我创建了一个 FULL Join 并进行了查询,它为我提供了Makeflag所有数量为零的产品。

如何操作输出,以便我可以将Makeflag所有数量变为 0 的产品的值更改为 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
4

2 回答 2

1

这应该可以解决问题

update AdventureWorks2008R2.Production.Product set MakeFlag = 1 
WHERE ProductID IN (
  SELECT ProductID FROM from Production.ProductInventory where Quantity = 0
)
于 2012-06-06T07:17:47.107 回答
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) 
于 2012-06-06T07:25:28.840 回答