方法:使用子查询和 NOT IN 子句
算法
如果我们有一份曾经订购过的客户名单,就很容易知道谁从未订购过。
我们可以使用下面的代码来获得这样的列表。
select customerid from orders
然后,我们可以使用 NOT IN 查询不在此列表中的客户。
select customers.name as 'Customers'
from customers
where customers.id not in
(
select customerid from orders
);
作者:LeetCode
链接:https://leetcode.cn/problems/customers-who-never-order/solutions/3566/cong-bu-ding-gou-de-ke-hu-by-leetcode/ 来源:力扣(LeetCode)