https://leetcode.com/problems/customers-who-never-order/

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

Suppose that a website contains two tables, the Customers table and the Orderstable. 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       |
+-----------+

代码:

# Write your MySQL query statement below
SELECT Name AS Customers FROM Customers WHERE Customers.Id NOT IN
(SELECT Orders.CustomerId FROM Orders)

  FH

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄