[HackerRank][SQL(Oracle)] The Blunder

728x90

 

※  The EMPLOYEES table is described as follows:

( Salary is per month. )
( 1000 < SALARY < 10^5 )

 

■  [Aggregation]  The Blunder

https://www.hackerrank.com/challenges/the-blunder/problem?isFullScreen=true 

Q.

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.

A.

SELECT CEIL( AVG( SALARY ) - AVG( TO_NUMBER(REPLACE(TO_CHAR(SALARY),'0','')) ) ) FROM EMPLOYEES;
 

 

반응형