[HackerRank] The Blunder

mzzzi·2022년 4월 21일
0

HackerRank SQL

목록 보기
32/52
post-thumbnail

MySQL > 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 key was broken until after completing the calculation. She wants your help finding the difference between her miscalculation (using The Blunder

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

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 = 206100 . Since it is equal to the integer 2061, it does not get rounded up.

My Answer


SELECT CEIL(AVG(SALARY) - AVG(REPLACE(SALARY, 0, '')))
FROM EMPLOYEES
profile
무럭무럭 성장하라🌳

0개의 댓글