题目地址:https://leetcode.com/problems/customers-who-never-order/
题解:选出从未订单的客户名字,很容易想到NOT IN操作,只要选出Coustmors ID不在Orders cunstomrId内的客户。
方法一:
select Name as Customers
from Customers
where Id not in(
select CustomerId from Orders);
方法二:可以将Customers表和Orders表左连接,然后取出CustomerId为空的即为未下单的用户
select Name as Customers
from Customers left join Orders on Customers.Id = Orders.CustomerId
where CustomerId is null