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 zeroes 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 measured in dollars per month and its value is < 10^5.
Sample Input
Sample Output
2061
Explanation
The table below shows the salaries without zeroes as they were entered by Samantha:
- actual average monthly salaries ==> AVG(Salary)
- salary without zeros ==> REPLACE(Salary, ‘0’, ‘’)
- miscalculated average monthly salaries ==> AVG(REPLACE(Salary, ‘0’, ‘’))
- difference between actual and miscalculated average salaries ==>
SELECT AVG(Salary) - AVG(REPLACE(Salary, ‘0’, ‘’)) - round the difference up to next integer ==>
SELECT CEIL(AVG(Salary) - AVG(REPLACE(Salary, ‘0’, ‘’))) - from EMPLOYEES table ==> FROM EMPLOYEES
SELECT CEIL(AVG(Salary) - AVG(REPLACE(Salary, '0', '')))
FROM EMPLOYEES;
'Algorithm > SQL' 카테고리의 다른 글
[SQL][HackerRank] Weather Observation Station 2 (0) | 2020.06.12 |
---|---|
[SQL][HackerRank] Top Earners (0) | 2020.06.12 |
[SQL][HackerRank] Population Density Difference (0) | 2020.06.11 |
[SQL][HackerRank] Higher Than 75 Marks (0) | 2020.06.11 |
[SQL][HackerRank] Average Population (0) | 2020.06.11 |