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.
Constraints
1000 < Salary < 10^5
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 98.00. The actual average salary is 2159.00.
The resulting error between the two calculations is 2159.00-98.00. Since it is equal to the integer 2061.00, it does not get rounded up.
[My Answer]
# relace함수를 통해 0을 다 없는 것처럼 만들어 준뒤 계산
SELECT
ROUND(AVG(SALARY))-ROUND(AVG(REPLACE(SALARY, '0','')))
FROM EMPLOYEES
키보드에 0이 고장난게... ㅠ
'Code Problems > SQL_ HackerRank' 카테고리의 다른 글
[Hacker Ranker] Weather Observation Station 2 (0) | 2021.11.07 |
---|---|
[Hacker Rank] Top Earners (0) | 2021.11.07 |
[HackerRank] Revising Aggregations, Populations (0) | 2021.11.07 |
[HackerRank] Revising Aggregations - The Count Function (0) | 2021.11.07 |
[HackerRank] New Company (0) | 2021.11.06 |