Growth ๐ŸŒณ/Practice ๐Ÿ’ป

[Hacker Rank] The Blunder

์ธ” 2022. 8. 20. 10:01

 

๐Ÿ“ข ๋ณธ ํฌ์ŠคํŒ…์— ํ™œ์šฉ๋˜๋Š” ๊ธฐ๋ณธ ๋ฌธ์ œ ๋ฐ ์ž๋ฃŒ ์ถœ์ฒ˜๋Š” HackerRank ์ž„์„ ๋ฐํž™๋‹ˆ๋‹ค.

https://www.hackerrank.com


โ–  ๋ฌธ์ œ

https://www.hackerrank.com/challenges/the-blunder/problem?isFullScreen=true 

 

The Blunder | HackerRank

Query the amount of error in Sam's result, rounded up to the next integer.

www.hackerrank.com

Samantha was tasked with calculating the average monthly salaries for all employees in the EMPLOYEES table, but did not realize her keyboard's  key was broken until after completing the calculation. She wants your help finding the difference between her miscalculation (using salaries with any zeros removed), and the actual average salary.

Write a query calculating the amount of error (i.e.:  actual - miscalculated average monthly salaries), and round it up to the next integer.

Input Format

The EMPLOYEES table is described as follows:

Note: Salary is per month.



โ–  ํ’€์ด

SELECT CEIL(avg(Salary)-avg(REPLACE(Salary,0,'')))
 FROM EMPLOYEES;

 

0 ๋ฒ„ํŠผ์ด ๊ณ ์žฅ๋‚˜์„œ ์ง์›๋“ค ์ž„๊ธˆ์—์„œ ์ˆซ์ž 0์ด ๋‹ค ๋น ์ ธ๋ฒ„๋ ธ๋‹ค๋Š” ... ์•„์ฐ” ..

์‹ค์ œ ์ „์ฒด ์ง์› ์›”๊ธ‰์˜ ํ‰๊ท ๊ณผ ์ž˜๋ชป ๊ณ„์‚ฐ๋œ ์›”๊ธ‰ ํ‰๊ท ์˜ ์ฐจ์ด๋ฅผ ๊ตฌํ•˜๊ณ ,์ฐจ์ด๋ฅผ ์˜ฌ๋ฆผํ•˜๋Š” ๊ฐ’์„ ์ถ”์ถœํ•˜๋Š” ์ฟผ๋ฆฌ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฌธ์ œ

 

์›”๊ธ‰์˜ ํ‰๊ท  ๊ตฌํ•˜๊ธฐ > avg ์‚ฌ์šฉ0์ด ๋น ์กŒ๋‹ค > 0์„ ๊ณต๋ฐฑ์œผ๋กœ ๋Œ€์ฒด - replace(s1, s2, s3) ํ•จ์ˆ˜ ์‚ฌ์šฉ๊ฒฐ๊ณผ๊ฐ’ ์˜ฌ๋ฆผ ์ฒ˜๋ฆฌ > ceil ์‚ฌ์šฉ