专栏首页Reck ZhangLeetCode 0183 - Customers Who Never Order

LeetCode 0183 - Customers Who Never Order

Customers Who Never Order

Desicription

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

Solution

SELECT Name
AS Customers
FROM Customers
WHERE Id NOT IN
(SELECT CustomerId FROM Orders)

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 【SQL刷题系列】:leetcode183 Customers Who Never Order

    假设一个网站包含两个表: Customers和Orders。写出一个SQL查询语句找出所有没有任何订单的顾客。

    Python数据科学
  • ​LeetCode刷题实战183:从不订购的客户

    算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试。所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就...

    程序IT圈
  • 【leetcode两题选手】MySQL类题目(四)

    某网站包含两个表,Customers 表和 Orders 表。编写一个 SQL 查询,找出所有从不订购任何东西的客户。

    看、未来
  • MySQL 排序、分页查询、聚合查询

    可以通过LIMIT <M> OFFSET <N>子句实现。每次显示最多 M 条,从第 N 条记录开始算

    Michael阿明
  • 【SQL刷题系列】:leetcode177 Nth Highest Salary

    【SQL刷题系列】:leetcode183 Customers Who Never Order

    Python数据科学
  • 【SQL刷题系列】:leetcode180 Consecutive Numbers

    【SQL刷题系列】:leetcode183 Customers Who Never Order

    Python数据科学
  • LeetCode MySQL 1511. Customer Order Frequency

    Write an SQL query to report the customer_id and customer_name of customers who ...

    Michael阿明
  • 第 3.3 节 Leetcode-Database 题解

    转载地址 https://github.com/CyC2018/CS-Notes/blob/master/README.md

    全栈程序员站长
  • LeetCode MySQL 1398. 购买了产品A和产品B却没有购买产品C的顾客

    请你设计 SQL 查询来报告购买了产品 A 和产品 B 却没有购买产品 C 的顾客的 ID 和姓名( customer_id 和 customer_name )...

    Michael阿明
  • LeetCode MySQL 1549. The Most Recent Orders for Each Product

    Write an SQL query to find the most recent order(s) of each product.

    Michael阿明
  • MySQL题集

    编写一个 SQL 查询,满足条件:无论 person 是否有地址信息,都需要基于上述两表提供 person 的以下信息:

    看、未来
  • IT部门存在的意义,谁是IT的客户

    今天看到这么一篇文章,转过来给做IT的朋友。我们必须审视自己存在的理由和意义,不仅要分清最终的客户,还得和同为IT的协作者、IT客户做好服务。你尽力让你的客户开...

    崔文远TroyCui
  • 16位顶级数据科学家语录

    Chief Data Scientist at The New York Times & Associate Professor of Applied Ma...

    哒呵呵
  • 亚麻BQ

    Leaders start with the customer and work backward. They work vigorously to earn ...

    王脸小
  • Top 5 Business Messaging Announcements at Facebook F8 2019

    Top 5 Business Messaging Announcements at Facebook F8 2019

    Spanz
  • Ultimate Facebook Messenger for Business Guide (Updated: Feb 2019)

    Ultimate Facebook Messenger for Business Guide (Updated: Feb 2019)

    Spanz
  • ZOJ 3607 Lazier Salesgirl (枚举)

    Lazier Salesgirl Time Limit: 2 Seconds Memory Limit: 65536 KB Kochiya S...

    ShenduCC
  • The Framing of the Developer

    Who framed Roger Rabbit? Talking about Software Development in companies is abou...

    仇诺伊
  • Talk to Anders about C#

    Chapter 13 of the book Masterminds of Programming

    极客中心

扫码关注云+社区

领取腾讯云代金券