leetcode 183. Customers Who Never Order

忘是亡心i 2022-07-19 01:56 177阅读 0赞

183. Customers Who Never Order

Question Editorial Solution

My Submissions

  • Total Accepted: 21129
  • Total Submissions: 64940
  • Difficulty: Easy

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.

  1. +----+-------+
  2. | Id | Name |
  3. +----+-------+
  4. | 1 | Joe |
  5. | 2 | Henry |
  6. | 3 | Sam |
  7. | 4 | Max |
  8. +----+-------+

Table: Orders.

  1. +----+------------+
  2. | Id | CustomerId |
  3. +----+------------+
  4. | 1 | 3 |
  5. | 2 | 1 |
  6. +----+------------+

Using the above tables as example, return the following:

  1. +-----------+
  2. | Customers |
  3. +-----------+
  4. | Henry |
  5. | Max |
  6. +-----------+

Subscribe to see which companies asked this question

  1. # Write your MySQL query statement below
  2. select c.Name as Customers
  3. from Customers c
  4. where not exists (select * from Orders o where o.customerId=c.id)

发表评论

表情:
评论列表 (有 0 条评论,177人围观)

还没有评论,来说两句吧...

相关阅读