584. 寻找用户推荐人

给定表 customer ,里面保存了所有客户信息和他们的推荐人。

+------+------+-----------+
| id | name | referee_id|
+------+------+-----------+
| 1 | Will | NULL |
| 2 | Jane | NULL |
| 3 | Alex | 2 |
| 4 | Bill | NULL |
| 5 | Zack | 1 |
| 6 | Mark | 2 |
+------+------+-----------+
写一个查询语句,返回一个编号列表,列表中编号的推荐人的编号都 不是 2。

对于上面的示例数据,结果为:

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

解题方案:

select `name` from customer where referee_id != 2 or referee_id is null
备注:在比较选择中,需要注意null

posted on 2020-10-18 12:18  random_boy  阅读(104)  评论(0编辑  收藏  举报

导航