设为首页 加入收藏

TOP

LeetCode——Customers Who Never Order(灵活使用NOT IN以及IN)
2019-10-10 11:17:54 】 浏览:91
Tags:LeetCode Customers Who Never Order 灵活 使用 NOT 以及
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       |
+-----------+

此题,竟然一时间没想到如何合理的解决方案,主要是有较长的时间没有使用INNOT IN.
SQL也是一个手熟的活,需要经常锻炼,以下是解题答案:

# Write your MySQL query statement below
SELECT Customers.Name AS Customers 
FROM Customers
WHERE Customers.Id NOT IN (SELECT CustomerId FROM Orders)
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇通过语句对SQL Server 表结构进行.. 下一篇LeetCode——Department Highest ..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目