183. 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 |
+-----------+ 查找所有从不订购任何东西的客户。 MySQL(821ms):
# Write your MySQL query statement below
SELECT Name AS Customers
FROM Customers
WHERE Id NOT IN (SELECT CustomerId
FROM Orders) ;
MySQL(803ms): 左外连接
# Write your MySQL query statement below
SELECT C.Name AS Customers
FROM Customers AS C LEFT JOIN Orders AS O
ON C.Id = O.CustomerId
WHERE O.CustomerId IS NULL ;
183. Customers Who Never Order的更多相关文章
- 【SQL】183. Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- leetcode 183. Customers Who Never Order
select Name as Customers from Customers where Id not in (select CustomerId from Orders);
- LeetCode 183. Customers Who Never Order (从不订购的客户)
题目标签: 题目给了我们 Customers 和 Orders 两个表格,让我们找到 从没订购过的客户. 首先从Orders 得到 订购过的CustomerId,然后再去Customers 里找 没有 ...
- [LeetCode] Customers Who Never Order 从未下单订购的顾客
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- 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]LeetCode183. 从不订购的客户 | Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- [LeetCode] 183. Customers Who Never Order_Easy tag: SQL
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 ...
- DataBase -- Customers Who Never Order
Question: Suppose that a website contains two tables, the Customers table and the Orders table. Writ ...
随机推荐
- FileProvider记录下
Mark下FileProvider,阿里巴巴Android开发手册有如下要求:[强制]应用间共享文件时,不要通过放宽文件系统权限的方式去实现,而应使用FileProvider. 知识点记录:1. An ...
- STM32之窗口看门狗
1.有个7位递减计数器(WWDG->CR),就这个计数器和窗口计数器(WWDG->CFR)决定什么时候喂狗.狗喂早了,复位——“早”体现在 计数器值(tr)>窗口值(wr),也就是计 ...
- Getting Private/Public IP address of EC2 instance using AWS-cli [closed]
For private IP address: aws ec2 describe-instances --instance-ids i-b78a096f | grep PrivateIpAddress ...
- 【C++ STL】List
1.结构 list使用一个double linked list(双向链表)来管理元素. 2. list 能力 list内部结构和vector或deque截然不同,所以与他们的区别: list不支持随机 ...
- Php扩展--seasLog日志扩展安装
安装/配置 编译安装 wge thttp://pecl.php.net/get/SeasLog-1.4.4.tgz tar -zxvfSeasLog-1.4.4.tgz cd SeasLog-1.4. ...
- iOS 隐藏导航栏下的黑线
一.找到导航栏下的黑线 // 寻找导航栏下的黑线 - (UIImageView *)findHairlineImageViewUnder:(UIView *)view { if ([view isKi ...
- Windows/Linux javac/java编译运行引入所需的jar包
> Windows 假设要引用的jar放在D:/test目录下,名字为t1.jar, java源文件放在D:/test/src目录下,名字为t2.java. 编译: javac -cp d: ...
- Gradle加载本地jar包
有时,我们需要的jar包不一定能在远程仓库中找到,这时我们需要加载本地的jar包. 加载单独的jar包 在项目底下添加libs目录,将jar包仍进libs目录 build.gradle配置如下: de ...
- 【BZOJ2287】消失之物 [分治][DP]
消失之物 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description ftiasch 有 N 个物品, ...
- js_数组去重效率对比
学习javascript已经快两年了,也不知道到了什么程度了. 说说我对javascript的理解,在电脑的世界里,只有数据. 数组,对象,字符串.对这些数据进行操作就可以完成很多业务逻辑,和页面的交 ...