2020-04-10
2020-04-10 本文已影响0人
DUYAN_bc77
查询从不
某网站包含两个表,Customers 表和 Orders 表。编写一个 SQL 查询,找出所有从不订购任何东西的客户。

Solution 1
*LEFT JOIN,IS NULL*
SELECT Name as Customers FROM Customers
LEFT JOIN Orders
ON Customers.Id=Orders.CustomerId
WHERE Orders.Id IS null;
左连接,结果晒选不为空的 “IS null”
Solution 2
*NOT IN*
Select name as Customers
From Customers
Where id not in (select CustomerId from orders)