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 |
+-----------+ 需求:查询没下单的客户 查询:

CREATE TABLE Customers(
Id TINYINT UNSIGNED,
Name VARCHAR(20)
)ENGINE=MyISAM CHARSET=utf8;

CREATE TABLE Orders(
Id TINYINT UNSIGNED,
CustomerId TINYINT UNSIGNED
)ENGINE=MyISAM CHARSET=utf8;


SELECT t1.Name
FROM Customers t1
WHERE NOT EXISTS(
SELECT * FROM Orders t2 WHERE t2.CustomerId=t1.Id
)

												

[LeetCode]-DataBase-Customers Who Never Order的更多相关文章

  1. LeeCode(Database)-Customers Who Never Order

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

  2. DataBase -- Customers Who Never Order

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

  3. LeetCode 183. Customers Who Never Order (从不订购的客户)

    题目标签: 题目给了我们 Customers 和 Orders 两个表格,让我们找到 从没订购过的客户. 首先从Orders 得到 订购过的CustomerId,然后再去Customers 里找 没有 ...

  4. leetcode 183. Customers Who Never Order

    select Name as Customers from Customers where Id not in (select CustomerId from Orders);

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

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

  6. LeetCode - Customers Who Never Order

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

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

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

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

  9. LeetCode Database题解

    175. Combine Two Tables 使用外连接即可. # Write your MySQL query statement below select FirstName, LastName ...

  10. [LeetCode] 429. N-ary Tree Level Order Traversal_ Easy

    Given an n-ary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

随机推荐

  1. CF 1141C Polycarp Restores Permutation

    Description An array of integers p1,p2,…,pnp1,p2,…,pn is called a permutation if it contains each nu ...

  2. [LeetCode] 227. 基本计算器 II

    题目链接: https://leetcode-cn.com/problems/basic-calculator-ii 难度:中等 通过率:33.2% 题目描述: 实现一个基本的计算器来计算一个简单的字 ...

  3. Linux 问题集

    解决E: Encountered a section with no Package: header错误 我的ubuntu机器上出现下面这个错误. Reading package lists... E ...

  4. 什么是 MicroPython ?它有什么优势?

    MicroPython 和 Python 都是一类 Python 的动态语言解释器. 若是在系统里安装了 Python 解释器,例如在 Windows 或者 Linux 命令行输入 python,进入 ...

  5. 10个用Java谋生非常有趣的方式

    令我惊讶的是,有些人觉得编程并不令人兴奋——只将它当作是一份枯燥的工作.不过,虽然可能的确有很多无聊的编程工作,但这并不意味着你不得不接受这些工作中的一个.程序员有各种各样的机会,运用他们的技能去做一 ...

  6. oracle链接报错shared memory realm does not exist

    问题描述: 前两天能够正常链接,今天来了突然不能链接,原因不详. 处理方法: 连接linux进行如下操作: 1.sqlplus /nolog 2.conn / as sysdba 3.startup ...

  7. jsp页面中JSTL如何处理日期格式

    引入fmt标签 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> 格 ...

  8. express做登录判断

    1)JWT试试 https://github.com/penguinab/express-jwt 2)express session https://github.com/whevether/reac ...

  9. Delphi 字符型数据

  10. icmp, IPPROTO_ICMP - Linux IPv4 ICMP 核心模块.

    DESCRIPTION 描述 本网络核心协议模块实现了基于 RFC792 协议中定义的<互联网控制报文协议>.它针对网络主机间通讯出错的情况作出回应并给出诊断信息.用户不能直接使用本模块. ...