LeetCode——Customers Who Never Order(灵活使用NOT IN以及IN)
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 |
+-----------+
此题,竟然一时间没想到如何合理的解决方案,主要是有较长的时间没有使用IN
与NOT IN
.
SQL
也是一个手熟的活,需要经常锻炼,以下是解题答案:
# Write your MySQL query statement below
SELECT Customers.Name AS Customers
FROM Customers
WHERE Customers.Id NOT IN (SELECT CustomerId FROM Orders)
PS:
如果您觉得我的文章对您有帮助,请关注我的微信公众号,谢谢!
LeetCode——Customers Who Never Order(灵活使用NOT IN以及IN)的更多相关文章
- [LeetCode] Customers Who Never Order 从未下单订购的顾客
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- LeetCode - Customers Who Never Order
Description: Suppose that a website contains two tables, the Customers table and the Orders table. W ...
- [SQL]LeetCode183. 从不订购的客户 | Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- LeetCode:Binary Tree Level Order Traversal I II
LeetCode:Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of ...
- LeeCode(Database)-Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- 【SQL】183. Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- 183. Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- DataBase -- Customers Who Never Order
Question: Suppose that a website contains two tables, the Customers table and the Orders table. Writ ...
- Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
随机推荐
- SparkSql 整合 Hive
SparkSql整合Hive 需要Hive的元数据,hive的元数据存储在Mysql里,sparkSql替换了yarn,不需要启动yarn,需要启动hdfs 首先你得有hive,然后你得有spark, ...
- MySQL分组查询统计
GROUP BY 1.有个店铺表,字段为区域id,设备数量,店铺名称,如下: 2.如何按区域 district 统计 每个区域的设备数量,SQL如下 SELECT district, SUM( dev ...
- linux--top工具分析
top分析工具详解 第一行:10:01:23 当前系统时间126 days, 14:29 系统已经运行了126天14小时29分钟(在这期间没有重启过)2 users 当前有2个用户登录系统 loa ...
- linux下查看程序占用多少内存
执行 ps auxVSZ(或VSS)列 表示,程序占用了多少虚拟内存:RSS列 表示, 程序占用了多少物理内存:虚拟内存可以不用考虑,它并不占用实际物理内存. 或执行top 命令 VIRT(或VSS) ...
- Rust多线程中的消息传递机制
代码说话. use std::thread; use std::sync::mpsc; use std::time::Duration; fn main() { let (tx, rx) = mpsc ...
- nm U -l库的
nm U -l库的
- C# WF 第12节 Timer控件
本节内容: 1:Timer控件的简介 2:实例1 : 不停的弹出,恶意exe 3:实例2: :流水灯 4:实例3:给流水灯加上计时器和在规定的时间进行播放音乐 1:Timer控件的简介 2:实例1 ...
- Codeforces Round #604 (Div. 2) 练习A,B题解
A题 链接 思路分析: 因为只需要做到相邻的不相同,利用三个不同的字母是肯定可以实现的, 所以直接先将所有的问号进行替换,比如比前一个大1,如果与后面的冲突,则再加一 代码(写的很烂): #inclu ...
- 【树状数组】2019徐州网络赛 query
(2)首先成倍数对的数量是nlogn级别的,考虑每一对[xL,xR](下标的位置,xL < xR)会对那些询问做出贡献,如果qL <= xL && qR >= xR, ...
- Java:String,int相互转化
int转String int a: a + “” String.valueOf(a) Interger.toString(a) 一般使用以上几种方法进行转化 第一种方法效率不好,ja ...