해커랭크 SQL문제_0828

starlikedh
|2021. 8. 28. 13:41

The Blunder

문제: 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.

풀이: 우선 문제 해석부터 해보자면 사만다는 직원 전원의 평균 월급을 계산하는 업무를 맡았으나 계산을 마치고 나서야 키보드의 0키가 고장난 것을 알았다. 그녀는 자신의 계산 착오(0을 제거한 급여 사용)와 실제 평균 급여 간의 차이를 찾는 데 도움을 받고자 한다. 오류 양(즉, 실제 - 잘못 계산된 평균 월 급여)을 계산하는 쿼리를 작성하고 다음 정수로 반올림하라는 문제라고 한다.

문제 해결을 위해서 실제랑 0을 제거한 Salary의 평균은 AVG로 구하여 빼주고,
이거를 CEIL 로 올림해주면 해결 가능한 문제. 당연히 FROM절에는 주어진 EMPLOYEES 테이블 활용하기.

 

'Database' 카테고리의 다른 글

해커랭크 SQL문제_1218  (0) 2021.12.18
해커랭크 SQL문제_1215  (0) 2021.12.15
Stored Function  (0) 2021.08.28
해커랭크 SQL문제_0807  (0) 2021.08.07
해커랭크 SQL문제_0805  (0) 2021.08.05