Skip to content

Commit 1c2740e

Browse files
committed
Leetcode :: Algorithms :: Customers Who Never Order Solution
1 parent 2c93bcb commit 1c2740e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Customers Who Never Order
3+
4+
Problem Statement:
5+
6+
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.
7+
8+
Table: Customers.
9+
10+
+----+-------+
11+
| Id | Name |
12+
+----+-------+
13+
| 1 | Joe |
14+
| 2 | Henry |
15+
| 3 | Sam |
16+
| 4 | Max |
17+
+----+-------+
18+
19+
Table: Orders.
20+
21+
+----+------------+
22+
| Id | CustomerId |
23+
+----+------------+
24+
| 1 | 3 |
25+
| 2 | 1 |
26+
+----+------------+
27+
28+
Using the above tables as example, return the following:
29+
30+
+-----------+
31+
| Customers |
32+
+-----------+
33+
| Henry |
34+
| Max |
35+
+-----------+
36+
37+
*/
38+
39+
/* Difficulty Level -- Easy*/
40+
41+
select Customers.Name as 'Customers'
42+
from Customers
43+
where Customers.Id not in
44+
(
45+
select CustomerId from Orders
46+
);
47+
48+

0 commit comments

Comments
 (0)