-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path183.从不订购的客户.sql
53 lines (52 loc) · 1.23 KB
/
183.从不订购的客户.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
--
-- @lc app=leetcode.cn id=183 lang=mysql
--
-- [183] 从不订购的客户
--
-- https://leetcode-cn.com/problems/customers-who-never-order/description/
--
-- database
-- Easy (61.00%)
-- Likes: 94
-- Dislikes: 0
-- Total Accepted: 20.9K
-- Total Submissions: 34.2K
-- Testcase Example: '{"headers": {"Customers": ["Id", "Name"], "Orders": ["Id", "CustomerId"]}, "rows": {"Customers": [[1, "Joe"], [2, "Henry"], [3, "Sam"], [4, "Max"]], "Orders": [[1, 3], [2, 1]]}}'
--
-- 某网站包含两个表,Customers 表和 Orders 表。编写一个 SQL 查询,找出所有从不订购任何东西的客户。
--
-- Customers 表:
--
-- +----+-------+
-- | Id | Name |
-- +----+-------+
-- | 1 | Joe |
-- | 2 | Henry |
-- | 3 | Sam |
-- | 4 | Max |
-- +----+-------+
--
--
-- Orders 表:
--
-- +----+------------+
-- | Id | CustomerId |
-- +----+------------+
-- | 1 | 3 |
-- | 2 | 1 |
-- +----+------------+
--
--
-- 例如给定上述表格,你的查询应返回:
--
-- +-----------+
-- | Customers |
-- +-----------+
-- | Henry |
-- | Max |
-- +-----------+
--
--
--
# Write your MySQL query statement below
select Name as Customers from Customers where Id not in (select CustomerId from Orders)