Problem Solving
[LeetCode] Calculate Special Bonus
luminous13
2022. 11. 6. 14:27
문제
https://leetcode.com/problems/calculate-special-bonus/
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: IF문 사용하기
if(조건식, 참일 경우 할당할 값, 거짓일 경우 할당할 값)
1
2
3
4
|
SELECT employee_id,
IF (employee_id%2 = 1 AND name NOT LIKE 'M%', salary, 0) AS bonus
FROM Employees
ORDER BY employee_id;
|
cs |
풀이2: CASE문 사용하기
CASE
WHEN 조건1 THEN 결과값1
WEHN 조건2 THEN 결과값2
ELSE 결과값
END
1
2
3
4
5
6
7
|
select employee_id,
CASE
WHEN employee_id%2 = 1 AND name NOT LIKE 'M%' THEN salary
ELSE 0
END AS bonus
from Employees
order by employee_id;
|
cs |