[해커랭크] The Blunder

june·2023년 3월 23일
0

SQL

목록 보기
9/31

The Blunder

https://www.hackerrank.com/challenges/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.: actual - miscalculated average monthly salaries), and round it up to the next integer.
SELECT CEIL(AVG(salary) - AVG(REPLACE(salary, 0, ''))) 
FROM employees

Lesson & Learned

REPLACE(string, from_string, new_string) 함수 : 문자열 내의 모든 하위 문자열을 새 하위 문자열로 바꾼다.
ROUND(AVG( ) - AVG( ), 0)를 시도했지만 round it up to the next integer 이라서 CEIL( )을 써야한다!

profile
나의 계절은

0개의 댓글