Database Leetcode Customers Who Never Order
2016-02-18 17:07
351 查看
题目:
Suppose that a website contains two tables, the
Table:
Table:
Using the above tables as example, return the following:
题意:
给定两个表Customers和Orders,分别表示的是用户表和订购物品表,要求找出那些没有订购过物品的用户姓名。也就是说,就是找出那些在Customers表中的Id在Orders中没有出现过的用户姓名。考虑用not in来做。
代码如下:
select Name as Customers from Customers where Id not in (select CustomerId from Orders);
Suppose that a website contains two tables, the
Customerstable and the
Orderstable. 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);
相关文章推荐
- OC在声明属性时的写法@interface的区别
- Java核心技术学习笔记之一:Java的基本程序设计结构
- 闭包 js
- QQ音乐for mac~下载歌曲到本地
- JavaScript逻辑运算
- 【实战Java高并发程序设计 5】让普通变量也享受原子操作
- Struts2-3.struts.xml的action可以简写
- 【Linux.Python】Python进程后台启动
- 计算前后2行的时间差
- DOM遍历
- Struts2 OGNL的一个例子
- JavaScript位运算
- AndroidStudio中Git的使用
- 利用Android的媒体库,遍历SD卡中的音乐文件,并用Service制作简单的音乐播放
- Spring入门
- Mac下 yasm安装
- 11:连续出现的字符(1.9)
- 关于shell调用MySQL存储过程的问题
- IO 读取文件、写出到文件的普通方法
- bootstrap ACE treeview json生成