SELECT swg.warehouse_owner_goods_id,
(
SELECT IFNULL(SUM(scod.order_quantity - scod.processing_quantity - scod.processed_quantity - IFNULL(srod.wait_out_return_quantity,0)),0)
FROM store_customer_order sco
INNER JOIN store_customer_order_details scod ON sco.customer_order_id = scod.customer_order_id
LEFT JOIN store_return_order_details srod
ON srod.customer_order_details_id = scod.customer_order_details_id AND srod.warehouse_owner_goods_id = swg.warehouse_owner_goods_id
-- ON srod.customer_order_details_id = scod.customer_order_details_id AND srod.warehouse_owner_goods_id = scod.warehouse_owner_goods_id
WHERE scod.warehouse_owner_goods_id = swg.warehouse_owner_goods_id
AND sco.customer_order_status IN (10, 15, 20)
) AS soldCount
FROM store_warehouse_owner_goods swg
WHERE (swg.goods_owner_id = 269886917817057280 AND swg.warehouse_owner_goods_id = 269887534304247808);
以上SQL, SELECT型子查詢, 不管是相關(guān)子查詢還是獨立子查詢, 在MySQL的8.0.25版本中都可以運行正常.
但是在8.0.18-X-Cluster-1.0.8版本中,獨立子查詢可以運行,相關(guān)子查詢運行失敗,失敗提示如下:
Error Code: 1054. Unknown column 'swg.warehouse_owner_goods_id' in 'on clause'