Milky's note

[HackerRank](E) The Blunder 본문

SQL/SQL 코딩 테스트-HackerRank

[HackerRank](E) The Blunder

밀뿌 2022. 3. 25. 16:46

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  0 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.

 

 

[답]

-mysql

select ceil(avg(salary) - avg(replace(salary,0,''))) from EMPLOYEES

 

문제가 엄청 긴데, 결국 지금 급여의 평균에서 0을 제거한 급여의 평균을 뺀 값에 올림 처리를 해주면 된다.

여기에서 헷갈리는 점이 있는데 앞에는 반올림을 하여라였고 지금은 무조건 올림을 하는 조건이다.

그래서 ceil을 사용해주었다. 문제에서 숫자 처리 부분을 잘 읽어야겠다.

  • ceil : 올림 (숫자)
  • round : 반올림 (숫자, (나타낼 소수점 뒤 자리수))
  • truncate : 버림 (숫자, 자리수)
Comments