码迷,mamicode.com
首页 > 数据库 > 详细

[LeetCode] 584. Find Customer Referee_Easy tag: SQL

时间:2018-08-29 01:08:24      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:res   lis   --   err   red   data   ati   lex   weight   

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

标签:res   lis   --   err   red   data   ati   lex   weight   

原文地址:https://www.cnblogs.com/Johnsonxiong/p/9551557.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!