You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In SQL, id is the primary key column for this table.
27
+
Each row of this table indicates the id of a customer, their name, and the id of the customer who referred them.
28
+
</pre>
29
+
30
+
<p> </p>
31
+
32
+
<p>Find the names of the customer that are <strong>not referred by</strong> the customer with <code>id = 2</code>.</p>
33
+
34
+
<p>Return the result table in <strong>any order</strong>.</p>
35
+
36
+
<p>The result format is in the following example.</p>
37
+
38
+
<p> </p>
39
+
<p><strongclass="example">Example 1:</strong></p>
40
+
41
+
<pre>
42
+
<strong>Input:</strong>
43
+
Customer table:
44
+
+----+------+------------+
45
+
| id | name | referee_id |
46
+
+----+------+------------+
47
+
| 1 | Will | null |
48
+
| 2 | Jane | null |
49
+
| 3 | Alex | 2 |
50
+
| 4 | Bill | null |
51
+
| 5 | Zack | 1 |
52
+
| 6 | Mark | 2 |
53
+
+----+------+------------+
54
+
<strong>Output:</strong>
55
+
+------+
56
+
| name |
57
+
+------+
58
+
| Will |
59
+
| Jane |
60
+
| Bill |
61
+
| Zack |
62
+
+------+
63
+
</pre>
64
+
65
+
<!-- description:end -->
66
+
67
+
## Solutions
68
+
69
+
<!-- solution:start -->
70
+
71
+
### Solution 1: Conditional Filtering
72
+
73
+
We can directly filter out the customer names whose `referee_id` is not `2`. Note that the customers whose `referee_id` is `NULL` should also be filtered out.
0 commit comments