[英]How can I remove subquery?
I need to remove the subquery.我需要删除子查询。 But I must maintain the condition.
但我必须保持状态。 What can I do?
我能做什么?
(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)
You can move the condition in the ON
clause:您可以在
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
......................
Also:还:
COUNT(CAST(cus_ord.customer_id AS INT))
is equivalent to just:相当于:
COUNT(cus_ord.customer_id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.