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 ...
随机推荐
- liteos CPU占用率(十六)
1. 概述 1.1 基本概念 CPU(中央处理器, Central Processing Unit)占用率可以分为系统CPU占用率和任务CPU占用率两种. 系统CPU占用率(CPU Percent)是 ...
- liteos分散加载(十四)
1. 概述 1.1 基本概念 分散加载是一种实现特定代码快速启动的技术,通过优先加载特定代码到内存,达到缩短从系统开机到特定代码执行的时间.可被应用来实现关键业务的快速启动. 嵌入式系统通过uboot ...
- Anaconda3使用
1.使用conda安装各种包到指定路径下的环境, conda install --prefix=/home/xxx/PycharmProjects/project_01/env numpy 2.安装指 ...
- ACM-ICPC 2018 焦作网络赛
题目顺序:A F G H I K L 做题链接 A. Magic Mirror 题意:判断 给出的 字符串 是否等于"jessie",需要判断大小写 题解:1.用stl库 tolo ...
- Html学习之一(锚点链接的使用,页面间的跳转)
页面一: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...
- 201271050130-滕江南-《面向对象程序设计(java)》第十四周学习总结
201271050130-滕江南-<面向对象程序设计(java)>第十四周学习总结 项目 内容 这个作业属于哪个课程 <任课教师博客主页链接> https://www.cnbl ...
- python 绘制词云图
1. 先下载并安装nltk包,准备一张简单的图片存入代码所在文件目录,搜集英文停用词表 import nltk nltk.download() 2. 绘制词云图 import re import nu ...
- IOI2015 boxes纪念品盒
BZOJ 4368: [IOI2015]boxes纪念品盒 BZOJ传送门 Description IOI2015开幕式正在进行最后一个环节.按计划在开幕式期间,每个代表队都将收到由主办方发放的一个装 ...
- 【day07】php
一.数组(Array) 1.数组:一组数据的集合 2.数组的分类: 索引数组:键名称是整数,编号从0开始 关联数组:键名称是字符串 3.定义一维数组 ...
- 【day05】php
一.时间日期函数库 1.安装:时间日期函数库PHPCORE组成部分 2. (1)date_default_timezone_set(string $timezone) 设置时区 ...
