순간을 기록으로

[LeetCode] Calculate Special Bonus 본문

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

 

'Problem Solving' 카테고리의 다른 글

[LeetCode] Delete Duplicate Emails  (0) 2022.11.06
[LeetCode] Swap Salary  (0) 2022.11.06
[Java] 신기한 소수 찾기_백준_2023  (0) 2022.10.28
[Java] 백준_ABCDE_13023  (0) 2022.08.19
[Java] 백준_신기한 소수_2023  (0) 2022.08.17
Comments