HackerRank/SQL

[hackerrank] The Blunder

예쁜꽃이피었으면 2022. 8. 25. 09:48

[hackerrank] Prepare > SQL > Aggregation > 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 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

.

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 . The actual average salary is .

The resulting error between the two calculations is . Since it is equal to the integer , it does not get rounded up.

[MYSQL]

 

 

[ORCALE]

select round( avg(salary)-avg(resalary),0)
from (
        select salary ,replace(salary,'0','') resalary
        from employees
    );

통과안됨.

 

select CEIL( avg(salary)-avg(resalary))
from (
        select salary ,replace(salary,'0','') resalary
        from employees
    );

 

- 소수점 올림 : CEIL
- 소수점 반올림 : ROUND
- 소수점 버림 : TRUNC

반응형

'HackerRank > SQL' 카테고리의 다른 글

[hackerrank] Weather Observation Station 2  (0) 2022.08.31
[hackerrank] Top Earners  (0) 2022.08.31
[hackerrank] Population Density Difference  (0) 2022.08.24
[hackerrank] Japan Population  (0) 2022.08.24
[hackerrank] Average Population  (0) 2022.08.24