[LeetCode] 584. Find Customer Referee_Easy tag: SQL

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode] 584. Find Customer Referee_Easy tag: SQL相关的知识,希望对你有一定的参考价值。

Given a table customer holding customers information and the referee.

+------+------+-----------+
| 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:

+------+
| name |
+------+
| Will |
| Jane |
| Bill |
| Zack |
+------+

 

note: 要用 is Null 和 != .

Code

SELECT name FROM customer WHERE referee_id != 2 OR referee_id IS NULL

 

以上是关于[LeetCode] 584. Find Customer Referee_Easy tag: SQL的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode(162):Find Peak Element

Leetcode总结之Union Find

LeetCode 436. Find Right Interval

LeetCode 724. Find Pivot Index

MySQL 练习<1>

MySQL 练习<1>