题目
题目难度:简单
某网站包含两个表,Customers 表和 Orders 表。编写一个 SQL 查询,找出所有从不订购任何东西的客户。
Id | Name |
---|---|
1 | Joe |
2 | Henry |
3 | Sam |
4 | Max |
Orders 表:
Id | CustomerId |
---|---|
1 | 3 |
2 | 1 |
解题
两个表做左连接,然后找出不在近视表的学生
则就是要添加where b.列名 is null
注意是is null 不是=null
SELECT a.Name as Customers
FROM Customers as a
LEFT JOIN Orders as b
ON a.Id = b.CustomerId
where b.CustomerId is null;