解决方案


方法:使用子查询和 NOT IN 子句

算法

如果我们有一份曾经订购过的客户名单,就很容易知道谁从未订购过。

我们可以使用下面的代码来获得这样的列表。

select customerid from orders;

然后,我们可以使用 NOT IN 查询不在此列表中的客户。

MySQL

select customers.name as 'Customers'
from customers
where customers.id not in
(
    select customerid from orders
);