查询从不
某网站包含两个表,Customers 表和 Orders 表。编写一个 SQL 查询,找出所有从不订购任何东西的客户。
Screen Shot 2020-04-10 at 9.54.50 AM.pngSolution 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)
网友评论