Snoopy 5. Calculate Special Bonus (1873)
코딩테스트/리트코드 SQL

5. Calculate Special Bonus (1873)

Sooyoon Jeong 2022. 12. 1.

👉https://leetcode.com/problems/calculate-special-bonus/description/?envType=study-plan&id=sql-i

 

Calculate Special Bonus - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com


🤔 문제 분석

1) Write an SQL query to calculate the bonus of each employee.

2) The bonus of an employee is 100% of their salary if the ID of the employee is an odd number and the employee name does not start with the character 'M'. The bonus of an employee is 0 otherwise.

3) Return the result table ordered by employee_id.

 

💡 풀이

SELECT employee_id, IF(MOD(employee_id, 2) = 1  AND name NOT LIKE "M%", salary, 0) AS bonus
FROM Employees
ORDER BY employee_id

댓글