Skip to content

Commit cd3c95a

Browse files
committed
customer referee
1 parent d29530b commit cd3c95a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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)

0 commit comments

Comments
 (0)