[LeetCode] 584. Find Customer Referee_Easy tag: SQL

博客围绕数据库查询展开,要求从存储客户信息和推荐人信息的表中,查询出未被ID为2的人推荐的客户列表,提示使用is Null和!= 进行查询,代码转载自相关博客。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Given a table customer holding customers information and the referee.

+------+------+-----------+
| id   | name | referee_id|
+------+------+-----------+
|    1 | Will |      NULL |
|    2 | Jane |      NULL |
|    3 | Alex |         2 |
|    4 | Bill |      NULL |
|    5 | Zack |         1 |
|    6 | Mark |         2 |
+------+------+-----------+

Write a query to return the list of customers NOT referred by the person with id '2'.

For the sample data above, the result is:

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

 

note: 要用 is Null 和 != .

Code

SELECT name FROM customer WHERE referee_id != 2 OR referee_id IS NULL

 

转载于:https://www.cnblogs.com/Johnsonxiong/p/9551557.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值