https://leetcode.com/problems/customers-who-never-order/description/
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.
Table: Customers.
+----+-------+
| Id | Name |
+----+-------+
| 1 | Joe |
| 2 | Henry |
| 3 | Sam |
| 4 | Max |
+----+-------+
Table: Orders.
+----+------------+
| Id | CustomerId |
+----+------------+
| 1 | 3 |
| 2 | 1 |
+----+------------+
Using the above tables as example, return the following:
+-----------+
| Customers |
+-----------+
| Henry |
| Max |
+-----------+
# Write your MySQL query statement below
SELECT Name AS Customers FROM Customers left outer join Orders
ON Customers.Id = Orders.CustomerId
where Orders.CustomerId is NULL
本文介绍了一个SQL查询案例,目标是从Customers和Orders两个表中找出所有从未下过订单的客户。通过使用LEFT OUTER JOIN和WHERE子句,我们可以有效地筛选出那些在Orders表中没有对应记录的客户。

137

被折叠的 条评论
为什么被折叠?



