问题描述:
给定表 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 |
+------+
思路:注意当条件为不等于什么的时候,查询不出来null的
错误的是:
select name
from customer
where referee_id !=2;
错误的运行结果:
正确的sql:
select name
from customer
where referee_id is null or referee_id !=2;
正确的运行结果:
我要刷100道算法题,第64道