Find Customer Referee Problem


Description

LeetCode Problem 584.

Given a table customer holding customers information and the referee.

1
2
3
4
5
6
7
8
9
10
+------+------+-----------+
| id   | name | referee_id|
+------+------+-----------+
|    1 | Will |      NULL |
|    2 | Jane |      NULL |
|    3 | Alex |         2 |
|    4 | Bill |      NULL |
|    5 | Zack |         1 |
|    6 | Mark |         2 |
+------+------+-----------+

Write a query to return the list of customers NOT referred by the person with id ‘2’.

For the sample data above, the result is:

1
2
3
4
5
6
7
8
+------+
| name |
+------+
| Will |
| Jane |
| Bill |
| Zack |
+------+


MySQL Solution

1
2
3
select name
from customer
where referee_id != '2' or referee_id is null




Related Posts

Investments In 2016 Problem

LeetCode 585. Write a query to print the sum of...

Count Student Number In Departments Problem

LeetCode 580. A university uses 2 data tables, student and...

Classes More Than 5 Students Problem

LeetCode 596. Please list out all classes which have more...

Find Customer Referee Problem

LeetCode 584. Given a table customer holding customers information and...

Customer Placing The Largest Number Of Orders Problem

LeetCode 586. Query the customer_number from the orders table for...

Big Countries Problem

LeetCode 595. Write a SQL solution to output big countries’...