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 |
+-----------+

此题,竟然一时间没想到如何合理的解决方案,主要是有较长的时间没有使用INNOT 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)的更多相关文章

  1. [LeetCode] Customers Who Never Order 从未下单订购的顾客

    Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...

  2. LeetCode - Customers Who Never Order

    Description: Suppose that a website contains two tables, the Customers table and the Orders table. W ...

  3. [SQL]LeetCode183. 从不订购的客户 | Customers Who Never Order

    Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...

  4. LeetCode:Binary Tree Level Order Traversal I II

    LeetCode:Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of ...

  5. LeeCode(Database)-Customers Who Never Order

    Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...

  6. 【SQL】183. Customers Who Never Order

    Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...

  7. 183. Customers Who Never Order

    Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...

  8. DataBase -- Customers Who Never Order

    Question: Suppose that a website contains two tables, the Customers table and the Orders table. Writ ...

  9. Customers Who Never Order

    Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...

随机推荐

  1. __rpm.so: underfined symbol : rpmpkgverifySigs 故障分析

    前言: 近期漏洞修复频繁,各种组件需要升级,经多次碰撞,发现 yum update 来升级组件是最有效最安全的方式(绿盟通过版本比对的扫描结果可以忽略). 然而,各家的设备各家管,一到升级就发现一堆问 ...

  2. CUDA -- 内存分配

    CUDA可以认为是一个由软件和硬件构成的并行计算系统,其依赖于GPU的并行计算单元,CUDA有类C的API,方便程序编写.其依赖于CPU和GPU的异构体系,通过在CPU上串行执行环境初始化.内存分配. ...

  3. Octave教程

    Windows安装Octave http://wiki.octave.org/Octave_for_Microsoft_Windows 基本操作(Basic Operations) octave:1& ...

  4. 日常学习python

    一.条件语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语句的执行过程: Python程序语言指定任何非0和非空(nu ...

  5. ResultMap(还没细看)

    前言 MyBatis是基于“数据库结构不可控”的思想建立的,也就是我们希望数据库遵循第三范式或BCNF,但实际事与愿违,那么结果集映射就是MyBatis为我们提供这种理想与现实间转换的手段了,而res ...

  6. 洛谷P1283 平板涂色 &&一本通1445:平板涂色

    题目描述 CE数码公司开发了一种名为自动涂色机(APM)的产品.它能用预定的颜色给一块由不同尺寸且互不覆盖的矩形构成的平板涂色. 为了涂色,APM需要使用一组刷子.每个刷子涂一种不同的颜色C.APM拿 ...

  7. Paper | Learning convolutional networks for content-weighted image compression

    目录 摘要 故事要点 模型训练 发表在2018年CVPR. 以下对于一些专业术语的翻译可能有些问题. 摘要 有损压缩是一个优化问题,其优化目标是率失真,优化对象是编码器.量化器和解码器(同时优化). ...

  8. Gin实现依赖注入

    前言 依赖注入的好处和特点这里不讲述了,本篇文章主要介绍gin框架如何实现依赖注入,将项目解耦. 项目结构 ├── cmd 程序入口 ├── common 通用模块代码 ├── config 配置文件 ...

  9. 【笔记】Clean Code(持续更新)

    这个暑假出来实习,第一次体会到在一个团队中开发的体验,与网上的网站看到的大为不同,以前看网上说什么程序员写了屎山代码,写了一堆模糊的注释或者说垃圾代码不写注释. 但在我的实习体验中,代码虽然看起来很多 ...

  10. 移动端js触摸touch详解(附带案例源码)

    移动端触摸滑动原理详解案例,实现过程通过添加DOM标签的触摸事件监听,并计算触摸距离,通过距离坐标计算触摸角度,最后通过触摸角度去判断往哪个方向触摸的. 触摸的事件列表 触摸的4个事件: touchs ...