SQL-每日一题【584.寻找用户推荐人】

题目

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

写一个查询语句,返回一个客户列表,列表中客户的推荐人的编号都 不是 2。

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

  

解题思路

1.题目要求查询列表中客户的推荐人的编号都 不是 2 和为 null 的客户。我们直接使用 where 来进行筛选,

referee_id != 2 or referee_id is null

代码实现

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

测试结果

猜你喜欢

转载自blog.csdn.net/lucky_1314520/article/details/131608509