我有两张 table 。第一个表是 Shipping
,其中包含 Product
、Quantity
和 ID
列。第二个表是 Inventory
,其中包含 Product
和 Total
列。
我想获取 Shipping.Quantity
的值,并从 Inventory.Total
中的值减去它,其中 Product
值与每个表和 Shipping.ID
都是 url ($onum
) 中的值。然后我想将该产品的新值设置为 Inventory.Total。
我能想到的最好的:
UPDATE Inventory.Total
CROSS JOIN Shipping
SET Inventory.total=(Inventorytotal-Shipping.Quantity)
WHERE Inventory.Product=Shipping.Product
AND Shipping.ID=$onum
最佳答案
UPDATE Inventory join Shipping
ON Inventory.Product=Shipping.Product
SET Inventory.Total=Inventory.Total-Shipping.Quantity
WHERE Shipping.ID=$ID
关于mysql - 从第二个表中的值减去一个表中的值 - 将结果设置为第二个表中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13235911/