首页 > 数据库 >数据库题(一)——寻找推荐人不是2的客户

数据库题(一)——寻找推荐人不是2的客户

时间:2023-02-13 00:12:28浏览次数:42  
标签:推荐人 NULL 数据库 referee 客户 null +------+------+-----------+ id

题目

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

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

我的解法

select name from customer where referee_id !=2 or referee_id is null;

避雷点

1.MySQL中 <> 和 != 是等价的,都不会查询出为空的数据
2. =null 是查不出等于空的数据,只能用 is null
3.不等于空可以用 is not null,或者 !=null

标签:推荐人,NULL,数据库,referee,客户,null,+------+------+-----------+,id
From: https://www.cnblogs.com/yatya/p/17115066.html

相关文章