Skip to content

Commit 1cc2120

Browse files
add 02
1 parent df5973d commit 1cc2120

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"editor.formatOnPaste": true
2+
"editor.formatOnSave": true
33
}

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Leetcode | Top SQL 50
22

3-
01. [Recyclable and Low Fat Products](solutions/01.1757.recyclable-and-low-fat-products/README.md)
3+
1. [Recyclable and Low Fat Products](solutions/01.1757.recyclable-and-low-fat-products/README.md)
4+
2. [Find Customer Referee](solutions/02.0584.find-customer-referee/README.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
comments: true
3+
difficulty: Easy
4+
tags:
5+
- Database
6+
---
7+
8+
<!-- problem:start -->
9+
10+
# [584. Find Customer Referee](https://leetcode.com/problems/find-customer-referee)
11+
12+
## Description
13+
14+
<!-- description:start -->
15+
16+
<p>Table: <code>Customer</code></p>
17+
18+
<pre>
19+
+-------------+---------+
20+
| Column Name | Type |
21+
+-------------+---------+
22+
| id | int |
23+
| name | varchar |
24+
| referee_id | int |
25+
+-------------+---------+
26+
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>&nbsp;</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>&nbsp;</p>
39+
<p><strong class="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.
74+
75+
<!-- tabs:start -->
76+
77+
#### MySQL
78+
79+
```sql
80+
# Write your MySQL query statement below
81+
SELECT name
82+
FROM Customer
83+
WHERE IFNULL(referee_id, 0) != 2;
84+
```
85+
86+
<!-- tabs:end -->
87+
88+
<!-- solution:end -->
89+
90+
<!-- problem:end -->

0 commit comments

Comments
 (0)