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 |
+-----------+
思路一:用IN
select Name from Customers where Id not in (select CustomerId from Orders);
思路二:用exists
select Name from Customers c where not exists (select Id from Orders o where c.Id = o.CustomerId);
思路三:用左连接
select Name from Customers c left join Orders o on c.Id = o.CustomerId where o.Id is NULL;
Customers Who Never Order的更多相关文章
- [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 ...
- 【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 - Customers Who Never Order
Description: Suppose that a website contains two tables, the Customers table and the Orders table. W ...
- 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 ...
- 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 qu ...
- 分别针对Customers表与Order表的通用查询操作
1.针对customers表通用的查询操作 CustomerForQuery package com.aff.PreparedStatement; import java.lang.reflect.F ...
随机推荐
- Spinner 通过XML形式绑定数据时 无法从String.xml中读取数组
在android应用程序中,通过XML形式给Spinner绑定数据,如果把数组放在系统的string.xml文件里,那么就有可能在运行时无法找到,导致程序异常结束,解决方法是自建一个XML文件来存放数 ...
- 06_android虚拟机介绍 05_sdkManager介绍
如果你不对SDK Manager进行设置,它默认会去谷歌官网下载最新的内容.由于官网被墙了,要么你FQ要么去设置代理.通过代理去下载相关的内容. 每一个android版本都对应着一个API的版本号.如 ...
- JDBC编程之数据查询
----------------siwuxie095 JDBC 编程之数据查询 首先下载 MySQL 的 JDBC 驱动 ...
- ubuntu使用root权限登录的设置方法
Ubuntu系统默认是不允许用户以root身份登录的,在网上找到的方法如下: 1.首先设置root密码,利用现有管理员帐户登陆Ubuntu,在终端执行命令:sudo passwd root,接着输入密 ...
- 【vue2.X+iview2.x】iView在非 template/render 模式下标签的转化
iView在非 template/render 模式下标签的转化. 以下组件,在非 template/render 模式下组件名要分隔: DatePicker:date-picker FormItem ...
- 关于java中的编码问题
ok,今天搞了一天都在探索java字符的编码问题.十分头疼.最后终于得出几点: 1.网上有很多博客说判断一个String的编码的方法是通过如下代码;但其实这个代码完全是错的,用一种编码decode后, ...
- 每次选中数组中的N条数据, 如果让每条数据被选中的次数做到平均??
经常有这样的需求, 有一组数据, 每次展示其中的1条或N条,希望每条数据展示量可以做到平均. 一开始想依次展示每条数据并做记录,整组数据全展示一遍之后清除记录, 然后一直循环下去. 实现的过程中又觉得 ...
- 【mybatis批量插入】
mybatis批量插入操作: MySQL:1.INSERT INTO TABLE_NAME(ID,NAME)VALUES(1,'张三'),(2,'李四') 2.INS ...
- .Net Core中依赖注入服务使用总结
一.依赖注入 引入依赖注入的目的是为了解耦和.说白了就是面向接口编程,通过调用接口的方法,而不直接实例化对象去调用.这样做的好处就是如果添加了另一个种实现类,不需要修改之前代码,只需要修改注入的地方将 ...
- How to generate rtabmap with a Realsense D435 or Xtion Pro Live?(如何使用Realsense D435或者Xtion Pro Live生成rtabmap?)
Ubuntu16.04,ROS kinetic 1.在ROS中安装rtabmap_ros包 sudo apt-get install ros-kinetic-rtabmap-ros 2. RGB-D相 ...