데이터베이스/SQL

584. Find Customer Referee

칼퇴시켜주세요 2022. 11. 30. 16:55
728x90

Customer 테이블에서 referee_id가 2가 아닌 사람의 name을 반환하는 SQL을 작성하는 문제이다.

테이블 스키마를 확인해보면 referee_id가 int 인것을 확인 할 수 있다. (엇.. 빈칸이 있네.. NULL인가??)

null을 다뤄보지 않아 referee_id = null 이렇게 처리하면 동작할줄 알았다... (null은 =연산이 안되는지 몰랐음...)

 

해결 방법은 referee_id is null 또는 isnull(referee_id)를 사용하면 된다.

# my solution
select name
from Customer
where referee_id != 2 or referee_id is null

# other solution
SELECT name FROM customer WHERE ISNULL(referee_id) OR (referee_id != 2)
반응형

'데이터베이스 > SQL' 카테고리의 다른 글

627. Swap Salary  (0) 2022.12.03
1873. Calculate Special Bonus  (0) 2022.12.03
183. Customers Who Never Order  (0) 2022.11.30
1757. Recyclable and Low Fat Products  (1) 2022.11.30
595. Big Countries  (0) 2022.11.30