关闭

183. Customers Who Never Order

96人阅读 评论(0) 收藏 举报
分类:

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       |
+-----------+


SELECT c.Name AS Customers

FROM Customers c
WHERE c.Id
NOT IN
(SELECT CustomerId FROM Orders);
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:31334次
    • 积分:1390
    • 等级:
    • 排名:千里之外
    • 原创:116篇
    • 转载:2篇
    • 译文:0篇
    • 评论:0条
    文章分类