홍동이의 성장일기

[LeetCode] 183. Customers Who Never Order 본문

Tool/SQL 코딩테스트 풀이

[LeetCode] 183. Customers Who Never Order

홍동2 2023. 8. 12. 20:14

 

Customers Who Never Order - LeetCode

Can you solve this real interview question? Customers Who Never Order - Table: Customers +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | name | varchar | +-------------+---------+ In SQL, id is the primary key colu

leetcode.com

 

Write a solution to find all customers who never order anything.

Return the result table in any order.

The result format is in the following example.

 

 

-- 내가 제출한 답
SELECT name as Customers
FROM Customers c LEFT JOIN Orders o
ON c.id = o.customerId
where o.customerId IS NULL
--1위 solutions
SELECT name as Customers
FROM Customers c
WHERE c.id NOT IN (SELECT customerID FROM Orders)

 

💡 개념정리

 

다중행 서브쿼리를 사용하면 더욱 간단하게 해결할 수 있었던 문제였다.

서브쿼리에 익숙해지기!

 


📍본 내용은 데이터리안 'SQL 데이터 분석 캠프 실전반' 을 수강하며 작성한 내용입니다.

728x90
Comments