如何删除子查询?

How can I remove subquery?

我需要删除子查询。但我必须保持状态。我能做什么?

(SELECT * FROM customer_orders where status=3)


SELECT cus.id,cus.customer_name,cus.mobile,cus.email, 
COUNT(CAST(cus_ord.customer_id AS INT)) AS Total_Order ,SUM(cus_ord.order_total_amt) AS Total_Amount
FROM customers as cus
LEFT JOIN (SELECT * FROM customer_orders where status=3) as cus_ord on CAST(cus_ord.customer_id AS INT)= CAST(cus.id AS INT)
GROUP BY CAST(cus.id AS INT) 

您可以在 ON 子句中移动条件:

......................
FROM customers AS cus LEFT JOIN customer_orders AS cus_ord 
ON CAST(cus_ord.customer_id AS INT) = CAST(cus.id AS INT) AND cus_ord.status = 3
......................

另外:

COUNT(CAST(cus_ord.customer_id AS INT))

等同于:

COUNT(cus_ord.customer_id)