๊ด€๋ฆฌ ๋ฉ”๋‰ด

Coding Planet

leetcode > 1873. Calculate Special Bonus ๋ณธ๋ฌธ

SQL

leetcode > 1873. Calculate Special Bonus

jhj.sharon 2023. 2. 5. 23:59
๋ฐ˜์‘ํ˜•

โœจ ๋ฌธ์ œ

 

๐Ÿ’ป์ฝ”๋“œ

/* Write your PL/SQL query statement below */
SELECT EMPLOYEE_ID, 
CASE WHEN MOD(EMPLOYEE_ID,2)=1 AND 
          NAME NOT LIKE 'M%' THEN SALARY ELSE 0
          END AS BONUS
FROM EMPLOYEES
ORDER BY EMPLOYEE_ID

 

๐Ÿ‘ฉ‍๐Ÿ’ป ํ’€์ด ๋ฐฉ๋ฒ•

  • ๋ฌธ์ œ์˜ ์กฐ๊ฑด ์—ฌ๋Ÿฌ๊ฐ€์ง€์ธ๋ฐ ๊ฐ๊ฐ์˜ ์กฐ๊ฑด์„ case when์œผ๋กœ ๊ตฌํ˜„ํ–ˆ๋‹ค.
  • employee_id๊ฐ€ odd number(ํ™€์ˆ˜)์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๊ธฐ ์œ„ํ•ด์„œ ๋‚˜๋จธ์ง€๋ฅผ ๊ตฌํ•˜๋Š” ํ•จ์ˆ˜์ธ MOD()๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค. ์ฆ‰ 2๋กœ ๋‚˜๋ˆด์„ ๋•Œ 1์ด ๋‚จ๋Š” ํ™€์ˆ˜์˜ ํŠน์„ฑ์„ ์ด์šฉํ•œ ๊ฒƒ์ด๋‹ค.
  • ์‚ฌ์›์˜ ์ด๋ฆ„์ด M์œผ๋กœ ์‹œ์ž‘ํ•˜์ง€ ๋ง์•„์•ผํ•œ๋‹ค๋Š” ๊ฒƒ์€ NOT LIKE 'M%'์œผ๋กœ ๊ตฌํ˜„ํ–ˆ๋‹ค.

๐Ÿ”” ๋Š๋‚€์ 

  • CASE ์ ˆ์ด๋‚˜ ์กฐ๊ฑด์ ˆ์„ ์‚ฌ์šฉํ•  ๋•Œ ์ž๊พธ END๋ฅผ ์“ฐ๋Š” ๊ฒƒ์„ ๊นŒ๋จน๋Š”๋‹ค ใ… 
๋ฐ˜์‘ํ˜•
Comments