给定表 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 |
+------+
题目来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/find-customer-referee
审题:查询列表中编号的推荐人的编号都 不是 2。的名字列表。
思考:查询referee_id不等于2的列表。
解题:也有可能没有人推荐。
select name from customer where referee_id != 2 or referee_id is null
知识点:where查询