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型子查询, 不管是相关子查询还是独立子查询, 在MySQL的8.0.25版本中都可以运行正常.
但是在8.0.18-X-Cluster-1.0.8版本中,独立子查询可以运行,相关子查询运行失败,失败提示如下:
Error Code: 1054. Unknown column 'swg.warehouse_owner_goods_id' in 'on clause'