문제. leetcode Database 183. Customers Who Never Order
SQL Schema & Explanation
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 |
+-----------+
출처 : leetcode Database 183. Customers Who Never Order
나의 풀이
# Write your MySQL query statement below
SELECT Name Customers FROM Customers c
WHERE c.Id NOT IN (SELECT CustomerId FROM ORDERS);
Orders 테이블에 customerId가 들어 있지 않은 경우가 주문하지 않은 고객이므로 Where Not In 구문을 이용하여 풀었습니다.
반응형
'Tests > Leetcode' 카테고리의 다른 글
[leetcode] MySQL > 596. Classes More Than 5 Students (0) | 2021.02.08 |
---|---|
[leetcode] MySQL > 180. Consecutive Numbers (0) | 2020.09.14 |
[leetcode] MySQL > 185. Department Top Three Salaries (0) | 2020.09.11 |
[leetcode] 177. Nth Highest Salary (MySQL) (0) | 2020.09.10 |
[leetcode] MySQL > 178. Rank Scores (0) | 2020.09.09 |
댓글