SQL

The Blunder

sawo11 2025. 5. 5. 03:07

문제 풀이 링크: https://www.hackerrank.com/challenges/the-blunder/problem?isFullScreen=true

 

The Blunder | HackerRank

Query the amount of error in Sam's result, rounded up to the next integer.

www.hackerrank.com


⌨️ The Blunder 문제 요약

  • EMPLOYEES 테이블의 salary 컬럼을 기반으로
    • 실제 평균 월급: AVG(salary)
    • 잘못된 평균 월급: salary에서 숫자 0을 제거한 값으로 계산한 평균
  • 두 평균의 차이를 구하고 결과는 올림(CEIL) 해서 정수로 출력

정답 풀이

  • CEIL: 올림 처리 함수로, 소수점을 올림하여 정수로 반환
  • CAST(REPLACE(salary, '0', '') AS UNSIGNED)
    • REPLACE(salary, '0', '')는 문자열을 반환하므로, 이를 CAST를 통해 숫자형(UNSIGNED)으로 변환

 

SELECT CEIL(
  AVG(salary) - AVG(CAST(REPLACE(salary, '0', '') AS UNSIGNED))
) AS error_amount
FROM EMPLOYEES;

'SQL' 카테고리의 다른 글

Weather Observation Station 19  (0) 2025.05.05
Draw The Triangle1, 2  (0) 2025.05.05
Top Earners  (0) 2025.05.05
Repeated Payments: Stripe SQL Interview Question  (0) 2025.05.03
Card Launch Success: JPMorgan SQL Interview Question  (0) 2025.05.03