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 ...
随机推荐
- vue.js解决刷新404找不到页面问题
1.将包解压到ROOT目录后创建WEB-INF目录 mkdir WEB-INF 2.进入WEB-INF目录,创建web.xml文件 cd WEB-INF touch web.xml 3.编辑web.x ...
- Neural Networks and Deep Learning 笔记
1 Introduction to Deep Learning 介绍了神经网络的定义,有监督学习,分析了为什么深度学习会崛起 1.1 结构化数据/非结构化数据 结构化数据:有一个确切的数据库,有key ...
- Flask13 面试要能吹 、安装虚拟机、虚拟机全局设置、导入虚拟机文件、虚拟机局部设置
1 web开发工作的三个能力 1.1 开发思想 易维护:开发成本远低于维护成本 可扩展:随着访问量的增加会自动使用多个数据库 高可用:程序就像小强一样,开发的系统能够经得住狂风暴雨的吹残(例如:一台主 ...
- win7中配置eclipse连接Ubuntu内的hadoop
Hadoop java 分布式 云计算 数据库 目录[-] 1.设置Ubuntu静态IP: 1)配置网卡参数到interfaces文件: 2)重启网卡: 2.配置Ubuntu的hosts: 3.配置V ...
- 使用GEO数据库来筛选差异表达基因,KOBAS进行KEGG注释分析
前言 本文主要演示GEO数据库的一些工具,使用的数据是2015年在Nature Communications上发表的文章Regulation of autophagy and the ubiquiti ...
- 通过命令查看jboss的错误日志文件
链接jboss: ssh ip -l jboss
- NIO和Reactor
本文参考Doug Lea的Scalable IO in Java. 网络服务 随着网络服务的越来越多,我们对网络服务的性能有了更高的要求,提供一个高性能,稳定的web服务是一件很麻烦的事情,所以有了n ...
- idea中java项目删除一个module
在idea中删除一个module,需要两步: 1. 使用Remove Module命令,快捷键是Delete 2. 经过第一步后,module图标上的小方块,消失,编程一个普通文件夹,这时使用Dele ...
- FUI- 我离钢铁侠还差几步?
本文来自网易云社区 作者:马宝 什么是FUI本文不累赘的可以自行Google,喜欢科幻的同学们都看一张图就能感受到FUI的魅力. 本文算是一篇所见即所的,可边学边干的原创教程.总结全文就一句话,&qu ...
- VS Code(待补充)
使用! 然后Tab 快速生成html文档结构 快速生成一个类 .类名 会有提示 .container.box .col-6*2 VisualStudio Code怎么同时编辑多处?