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 |
+-----------+ 查找所有从不订购任何东西的客户。 MySQL(821ms):
 # Write your MySQL query statement below
SELECT Name AS Customers
FROM Customers
WHERE Id NOT IN (SELECT CustomerId
FROM Orders) ;
MySQL(803ms):  左外连接
 # Write your MySQL query statement below
SELECT C.Name AS Customers
FROM Customers AS C LEFT JOIN Orders AS O
ON C.Id = O.CustomerId
WHERE O.CustomerId IS NULL ;

183. Customers Who Never Order的更多相关文章

  1. 【SQL】183. Customers Who Never Order

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

  2. leetcode 183. Customers Who Never Order

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

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

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

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

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

  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]LeetCode183. 从不订购的客户 | Customers Who Never Order

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

  7. [LeetCode] 183. Customers Who Never Order_Easy tag: SQL

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

  8. LeetCode - Customers Who Never Order

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

  9. DataBase -- Customers Who Never Order

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

随机推荐

  1. 【IntelliJ IDEA 12使用】导入外部包

    以前用eclipse,现在用IntelliJ IDEA,发现它确实是个很不错的工具. 用IntelliJ IDEA12这个版本导入外部JAR包,这样来操作,打开Project Structure,在m ...

  2. 通过java客户端连接hbase 注意事项

    1.通过Java客户端连接Hbase,其中hbase通过zookeeper去管理,需要注意的是客户端端口. 通过在浏览器端输入地址查看:http://192.168.3.206:60010/maste ...

  3. mysql 服务端事务和客户端事务对比分析

    之前做mysql事务测试的时候都是在mysql服务端存储过程里面包含事务. 例如: CREATE DEFINER=`root`@`localhost` PROCEDURE `Test`(out deb ...

  4. 51nod 1106 质数检测——Mr判素数

    质数检测一般都是根号n的写法 当然Mr判素数的方法可以实现log的复杂度2333 Mr判素数的话 我们根据费马小定理只要P是素数 那么另一个素数x 满足 x^P-1≡1(mod P) 同时 x^2%P ...

  5. nodejs入门教程之http的get和request简介及应用

    nodejs入门教程之http的get和request简介及应用 前言 上一篇文章,我介绍了nodejs的几个常用的模块及简单的案例,今天我们再来重点看一下nodejs的http模块,关于http模块 ...

  6. 多github帐号的SSH key切换

    我有两个github帐号,一个是个人所用,一个是为公司项目所用.如果是单用户(single-user),很方便,默认拿id_rsa与你的github服务器的公钥对比:如果是多用户(multi-user ...

  7. 安装FFMpeg CentOS 7

    https://linuxadmin.io/install-ffmpeg-on-centos-7/

  8. 【C语言】Coursera课程《计算机程式设计》台湾大学刘邦锋——Week6 String课堂笔记

    Coursera课程 <计算机程式设计>台湾大学 刘邦锋 Week6 String 6-1 Character and ASCII 字符变量的声明 char c; C语言使用一个位元组来储 ...

  9. 需要重刷整個 image 的時機 - 1

    最近遇到一個問題, gpio 讀出來的值與預期不同, 詳細描述如下: 首先手機 download 了一個完整的 daily build image , 接下來 不斷地修改 kernel 部分 code ...

  10. python基础===修改属性的值

    可以以三种不同的方式修改属性的值:直接通过实例进行修改:通过方法进行设置:通过方法进行递增(增加特定的值).下面依次介绍这些方法. class Car(): def __init__(self, ma ...