File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ -- 584. Find Customer Referee
2+
3+ -- Table: Customer
4+
5+ -- +-------------+---------+
6+ -- | Column Name | Type |
7+ -- +-------------+---------+
8+ -- | id | int |
9+ -- | name | varchar |
10+ -- | referee_id | int |
11+ -- +-------------+---------+
12+ -- In SQL, id is the primary key column for this table.
13+ -- Each row of this table indicates the id of a customer, their name, and the id of the customer who referred them.
14+
15+
16+ -- Find the names of the customer that are not referred by the customer with id = 2.
17+
18+ -- Return the result table in any order.
19+
20+ -- The result format is in the following example.
21+
22+
23+
24+ -- Example 1:
25+
26+ -- Input:
27+ -- Customer table:
28+ -- +----+------+------------+
29+ -- | id | name | referee_id |
30+ -- +----+------+------------+
31+ -- | 1 | Will | null |
32+ -- | 2 | Jane | null |
33+ -- | 3 | Alex | 2 |
34+ -- | 4 | Bill | null |
35+ -- | 5 | Zack | 1 |
36+ -- | 6 | Mark | 2 |
37+ -- +----+------+------------+
38+ -- Output:
39+ -- +------+
40+ -- | name |
41+ -- +------+
42+ -- | Will |
43+ -- | Jane |
44+ -- | Bill |
45+ -- | Zack |
46+ -- +------+
47+
48+
49+ SELECT name from Customer where id NOT IN (SELECT id FROM customer WHERE referee_id = 2 )
You can’t perform that action at this time.
0 commit comments