Skip to content

Commit be9c9e1

Browse files
committed
finish 183
1 parent 22dc110 commit be9c9e1

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# 183. Customers Who Never Order
2+
3+
- Difficulty: Easy.
4+
- Related Topics: .
5+
- Similar Questions: .
6+
7+
## Problem
8+
9+
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.
10+
11+
Table: ```Customers```.
12+
13+
```
14+
+----+-------+
15+
| Id | Name |
16+
+----+-------+
17+
| 1 | Joe |
18+
| 2 | Henry |
19+
| 3 | Sam |
20+
| 4 | Max |
21+
+----+-------+
22+
```
23+
24+
Table: ```Orders```.
25+
26+
```
27+
+----+------------+
28+
| Id | CustomerId |
29+
+----+------------+
30+
| 1 | 3 |
31+
| 2 | 1 |
32+
+----+------------+
33+
```
34+
35+
Using the above tables as example, return the following:
36+
37+
```
38+
+-----------+
39+
| Customers |
40+
+-----------+
41+
| Henry |
42+
| Max |
43+
+-----------+
44+
```
45+
46+
## Solution 1
47+
48+
```sql
49+
# Write your MySQL query statement below
50+
select a.Name as Customers
51+
from Customers a
52+
where a.Id not in (
53+
select b.CustomerId from Orders b
54+
)
55+
```
56+
57+
**Explain:**
58+
59+
nope.
60+
61+
**Complexity:**
62+
63+
* Time complexity :
64+
* Space complexity :
65+
66+
## Solution 2
67+
68+
```sql
69+
# Write your MySQL query statement below
70+
select a.Name as Customers
71+
from Customers a
72+
where not exists (
73+
select Id from Orders b where a.Id = b.CustomerId
74+
)
75+
```
76+
77+
**Explain:**
78+
79+
nope.
80+
81+
**Complexity:**
82+
83+
* Time complexity :
84+
* Space complexity :
85+
86+
## Solution 3
87+
88+
```sql
89+
# Write your MySQL query statement below
90+
select a.Name as Customers
91+
from Customers a
92+
left join Orders b
93+
on a.Id = b.CustomerId
94+
where b.CustomerId is null
95+
```
96+
97+
**Explain:**
98+
99+
nope.
100+
101+
**Complexity:**
102+
103+
* Time complexity :
104+
* Space complexity :

0 commit comments

Comments
 (0)