我有以下查询:
SELECT entity_id AS product_id FROM catalog_product_entity cpe
LEFT JOIN cataloginventory_stock_item csi ON csi.product_id = cpe.entity_id
WHERE cpe.type_id = 'configurable'
AND csi.is_in_stock = 0
AND (SELECT SUM(qty) FROM catalog_product_relation cpr LEFT JOIN cataloginventory_stock_item cisi ON cisi.product_id = cpr.child_id WHERE cpr.parent_id = cpe.entity_id) > 0
它返回以下结果:
product_id
-----------
912
906
894
559
364
我正在尝试根据上述查询结果中存在的表的 product_id更新表中的is_in_stock
列。cataloginventory_stock_item
我试图做的是:
UPDATE cataloginventory_stock_item
SET is_in_stock = 1
WHERE product_id IN (
SELECT entity_id AS product_id FROM catalog_product_entity cpe
LEFT JOIN cataloginventory_stock_item csi ON csi.product_id = cpe.entity_id
WHERE cpe.type_id = 'configurable'
AND csi.is_in_stock = 0
AND (SELECT SUM(qty) FROM catalog_product_relation cpr LEFT JOIN cataloginventory_stock_item cisi ON cisi.product_id = cpr.child_id WHERE cpr.parent_id = cpe.entity_id) > 0
)
我收到以下错误:
You can't specify target table 'cataloginventory_stock_item' for update in FROM clause
我似乎无法弄清楚如何重组查询以使其工作。任何帮助是极大的赞赏。