183. 从不订购的客户
题目链接:https://leetcode.cn/problems/customers-who-never-order/
题目描述:
我们可以先获得采购的客户名单,然后用NOT IN查询不在列表中的客户:
SELECT customer.name as 'Customers' //注意题目要求返回的列名为Customers FROM customers WHERE cunstomers.id NOT IN ( SELECT customerid FROM orders );
第二种解法是使用left join,使用left join连接customers和orders连接条件是 customers.id = orders.customersId and isnull(customersId)。
SELECT customer.name as 'Customers' FROM customers LEFT JOIN orders ON customers.id = orders.customerId WHERE ISNULL(customerId);