[leetcode]577. Employee Bonus

김준석·2024년 2월 5일

코딩테스트 - SQL

목록 보기
64/96

문제

https://leetcode.com/problems/employee-bonus/description/?envType=study-plan-v2&envId=top-sql-50

풀이

SELECT
    em.name,
    SUM(bonus) AS bonus 
FROM
    Employee em
    LEFT JOIN Bonus b
        ON em.empId=b.empId
GROUP BY
    em.empId
HAVING 1=1
    AND bonus<1000
    OR bonus IS NULL

후기

보너스를 못받은 인원도 있기 때문에 null값이 존재!
null값도 나오도록 하기 위해서는 where절에 꼭 위 코드처럼 넣어줘야 됨.

0개의 댓글