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.: 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.
Constraints
.
Sample Input

Sample Output
2061
Explanation
The table below shows the salaries without zeros as they were entered by Samantha:

Samantha computes an average salary of . The actual average salary is .
The resulting error between the two calculations is . Since it is equal to the integer , it does not get rounded up.
- 실제 평균 월급: AVG(SALARY)
- 0이 제거된 잘못된 월급: REPLACE(SALARY, '0', '')
- 잘못된 평균 월급 계산: AVG(...)
- 둘의 차이 계산 후 올림: CEIL(...)
select ceil(avg(salary) - avg(replace(salary, 0, ''))) from employees;
'Computer Science > SQL' 카테고리의 다른 글
SQL | HackerRank 성적에 따라 이름을 보여주는 리포트 만들기 CASE WHEN (0) | 2025.06.19 |
---|---|
SQL | HackerRank ROW_NUMBER()와 COUNT(*) OVER()를 활용하여 중앙값(Median) 구하기 (0) | 2025.06.18 |
SQL | HackerRank 이진 트리 노드 유형(Root, Inner, Leaf) 구분하는 쿼리 (0) | 2025.06.16 |
SQL | HackerRank MAX(CASE WHEN…)을 활용한 피벗(Pivot) 쿼리 (0) | 2025.06.15 |
SQL | HackerRank 문자열을 이어붙이기 (CONCAT) (0) | 2025.06.14 |