从Prestashop数据库更新数量

时间:2015-03-04 22:55:34

标签: mysql sql sql-update inner-join prestashop-1.6

我对UPDATE Prestashop数据库有一点问题。 我尝试从ps_stock_available更新数量。 我有2个数量需要更新。我的INNER JOIN工作。

id_product   id_product_attribute   upc           quantity
140          263                    90100014017   665

但是使用upc,我还需要让id_product用0更新其他id_product_attribute:

id_product   id_product_attribute   upc           quantity
140          0                      90100014017   675

SQL:

UPDATE ps_stock_available AS s
INNER JOIN ps_product_attribute AS ps ON ps.id_product_attribute = s.id_product_attribute
INNER JOIN ps_product AS p ON p.id_product = ps.id_product
SET s.quantity = s.quantity-1
WHERE ps.upc = 90100014017

更新第一个数量是有效的,但我不知道如何更新第二个数量。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:1)

我找到了解决方案!

SELECT sa.id_product, sa.id_product_attribute, sa.quantity, pa.upc
FROM ps_stock_available AS sa
LEFT OUTER JOIN ps_product_attribute AS pa ON pa.id_product_attribute = sa.id_product_attribute
WHERE sa.id_product = 140;