-
leetcode - 577. Employee BonusSQL 문제풀이 2022. 6. 30. 17:47
난이도 : Easy
Table: Employee
+-------------+---------+ | Column Name | Type | +-------------+---------+ | empId | int | | name | varchar | | supervisor | int | | salary | int | +-------------+---------+ empId is the primary key column for this table. Each row of this table indicates the name and the ID of an employee in addition to their salary and the id of their manager.
Table: Bonus
+-------------+------+ | Column Name | Type | +-------------+------+ | empId | int | | bonus | int | +-------------+------+ empId is the primary key column for this table. empId is a foreign key to empId from the Employee table. Each row of this table contains the id of an employee and their respective bonus.
Write an SQL query to report the name and bonus amount of each employee with a bonus less than 1000.
Return the result table in any order.
join을 활용한 방법
SELECT Employee.name , bonus FROM Employee LEFT JOIN Bonus ON Employee.empId = Bonus.empId WHERE bonus < 1000 OR bonus IS NULL
Accepted (94.55%)
ifnull을 활용한 방법
SELECT Employee.name , bonus FROM Employee LEFT JOIN Bonus ON Employee.empId = Bonus.empId WHERE IFNULL(bonus, 0) < 1000
Accepted (13.56%)
'SQL 문제풀이' 카테고리의 다른 글
leetcode - 1179. Reformat Department Table (0) 2022.07.01 leetcode - 1173. Immediate Food Delivery I (0) 2022.07.01 leetcode - 512. Game Play Analysis II (0) 2022.06.30 leetcode - 511. Game Play Analysis I (0) 2022.06.30 leetcode - 197. Rising Temperature (0) 2022.06.30