开发者

MySQL query to find customers who have made 0 orders / no orders

I would like to find those customers, who have not made any orders yet.

I have found some queries to find customer wise total no. of orders, but did not able t开发者_开发问答o find/get any query, which returns me those customers ids, which are not into orders table.

Also would like to sort the results by date, like in last month, last year etc.

Any help/idea would be appreciated.

Thanks !


How about

SELECT c.*
FROM Customers c LEFT JOIN
Orders o ON c.CustomerID = o.CustomerID
WHERE o.CustomerID IS NULL

or

SELECT c.*
FROM Customers c
WHERE NOT EXISTS (SELECT 1 FROM Orders o WHERE o.CustomerID = c.CustomerID)


select c.* from Customers c
where c.CustomerID NOT IN (select o.CustomerID from Orders o)


select customer_name from customer               
where customer_id not in (select customer_id from orders);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜