본문 바로가기
PROGRAMMING/LeetCode

[Leetcode] 183. Customers Who Never Order_해설, 풀이, 설명

by HYUNHP 2023. 1. 6.
반응형

안녕하세요, HELLO

 

오늘은 Leetcode 알고리즘 문제 '183. Customers Who Never Order'에 대해서 살펴보고자 합니다. 

 

알고리즘 문제, 코드, 해설 그리고 Leetcode에서 제공해준 solution 순서대로 정리하였습니다.


STEP 1. 'Customers Who Never Order' 알고리즘 문제

 

STEP 2. 'Customers Who Never Order' 코드(code)

 

STEP 3. 'Customers Who Never Order' 해설

 

STEP 4. 'Customers Who Never Order' solution

 

반응형

 

STEP 1. 'Customers Who Never Order' 알고리즘 문제

 

 

Write an SQL query to report all customers who never order anything. Return the result table in any order.

한 번도 구매한 이력이 없는 고객 정보를  '순서에 상관없이' 출력하는 SQL 쿼리 작성하면 됩니다.

 

The query result format is in the following example.

 


STEP 2. 'Customers Who Never Order' 코드(code)

 

■ Runtime: Runtime 588 ms, Beats 48.74%

 

# Write your MySQL query statement below

select Customers.name as Customers
from Customers
left join Orders on Orders.customerId = Customers.id
where Orders.id is Null
;

STEP 3. 'Customers Who Never Order' 해설

 

고객 정보 'Customers' 테이블과 주문 내역 'Orders'을 Left Join으로 연결하고, 주문 내역이 'Null'인 경우를 반환하는 것으로 쿼리를 작성했습니다. 

 

가장 성능이 좋은 쿼리를 살펴보니, join을 통해서 테이블을 만들지 않고 진행해도 되는 것을 알게 되었습니다.

 

728x90

 

STEP 4. 'Customers Who Never Order' solution

 

추가적으로, Leetcode에서 제공해준 solution 코드를 살펴보겠습니다.

 

■ Runtime: Runtime 381ms, Beats 0.24%

 

# Write your MySQL query statement below
select customers.name as 'Customers'
from customers
where customers.id not in
(
    select customerid from orders
);

■ 마무리

 

오늘은 Leetcode 알고리즘 문제 '183. Customers Who Never Order'에 대해서 알아봤습니다.

좋아요와 댓글 부탁드리며,

오늘 하루도 즐거운 날 되시길 기도하겠습니다 :)

감사합니다.

 

반응형

댓글