본문 바로가기
[업무 지식]/MySQL

[NULL] Find Customer Referee

by 에디터 윤슬 2024. 10. 23.
 

링크

https://leetcode.com/problems/find-customer-referee/description/

문제

Find the names of the customer that are not referred by the customer with id = 2.

Return the result table in any order.

The result format is in the following example.

정답

select name
from (
    select id,
            name,
            ifnull(referee_id, 0) as referee_id
    from customer
    ) a
where referee_id <> 2

해설

  • NULL 값 처리

새롭게 이해한 내용

  • NULL 값의 처리를 항상 염두에 둬서 실무에 사용