本文主要是介绍Database Leetcode Customers Who Never Order,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
Suppose that a website contains two tables, the Customers
table and the Orders
table. Write a SQL query to find all customers who never order anything.
Table: Customers
.
+----+-------+
| Id | Name |
+----+-------+
| 1 | Joe |
| 2 | Henry |
| 3 | Sam |
| 4 | Max |
+----+-------+
Table: Orders
.
+----+------------+
| Id | CustomerId |
+----+------------+
| 1 | 3 |
| 2 | 1 |
+----+------------+
Using the above tables as example, return the following:
+-----------+
| Customers |
+-----------+
| Henry |
| Max |
+-----------+
题意:
给定两个表Customers和Orders,分别表示的是用户表和订购物品表,要求找出那些没有订购过物品的用户姓名。也就是说,就是找出那些在Customers表中的Id在Orders中没有出现过的用户姓名。考虑用not in来做。
代码如下:
select Name as Customers from Customers where Id not in (select CustomerId from Orders);
这篇关于Database Leetcode Customers Who Never Order的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!