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. [20191013]oracle number类型存储转化脚本.txt

    [20191013]oracle number类型存储转化脚本.txt --//测试看看是否可以利用bc obase=100的输出解决问题.另外以前脚本忘记考虑尾数的四舍五入问题.--//也许编程就是 ...

  2. 传入一个Map<String,Long> 返回它按value排序后的结果

    //传入一个Map<String,Long> 返回它按value排序后的结果 sort为正序还是倒序(-1倒序),size为要几条数据 private static Map<Stri ...

  3. 并发修改异常ConcurrentModificationException

    1.简述:在使用 迭代器对象遍历集合时,使用集合对象修改集合中的元素导致出现异常 public static void main(String[] args) { List<Integer> ...

  4. c++ 模板特化与局部特化

    c++ 模板特化与局部特化 模板的由来是要处理泛化,也就是任何类型都可以处理.但是泛化的同时,如果针对某种特殊的类型,又更加效率的处理方法.c++提供针对特殊的类型,可以定义不同的处理方法.针对某种特 ...

  5. [Go] gocron源码阅读-groutine与channel应用到信号捕获

    直接使用go 函数名()可以开启一个grountine,channel可以接收信息并且如果没有数据时会阻塞住channel对应的是底层数据结构的引用,复制channel和函数传参都是拷贝的引用make ...

  6. [日常] 修复了grub引导问题

    上周遇到的神奇引导问题竟然被鬼使神差的修复好了.因为我的电脑是64位的也就是x86_64架构,并且是UEFI模式下,但是之前装的grub一直是grub-传统,并且一直是i386-pc平台也就是32位的 ...

  7. CentOS服务器apache绑定多个域名的方法

    这篇文章主要为大家详细介绍了CentOS服务器apache绑定多个域名的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 Apache是最流行的HTTP服务器软件之一,其以快速.可靠(稳定) ...

  8. c# 第37节 接口的实现与继承

    本节内容: 1:接口继承注意 2:开发封闭原则: 3:实例解释接口的作用 1:接口继承注意 接口的继承: :类继承具有单根性,接口可多重继承: :接口继承多个接口的时候,派生接口名与父接口用冒号隔开, ...

  9. Java:String,int相互转化

    int转String int a: a + “”    String.valueOf(a)    Interger.toString(a)    一般使用以上几种方法进行转化 第一种方法效率不好,ja ...

  10. 【Spring AOP】AOP核心概念(二)

    1. 横切关注点 对哪些方法进行拦截,拦截后怎么处理,这些关注点称之为横切关注点. 2. 切面(aspect)-- 本质上仅仅是一个类 类是对物体特征的抽象,切面就是对横切关注点的抽象. 3. 连接点 ...