CodingSpace

[HackerRank/SQL] Revising Aggregations - The Blunder 본문

HackerRank/SQL

[HackerRank/SQL] Revising Aggregations - The Blunder

개발자_조이킴 2022. 7. 17. 02:35

Problem. Revising Aggregations - The Blunder


Link.

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

 

Population Density Difference | HackerRank

Query the difference between the maximum and minimum city populations in CITY.

www.hackerrank.com


Description.

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.

 

 

EMPLOYEES 테이블


Key Point. 

SELECT,

 

AVG,

 

REPLACE,

 

CEIL, CEIL()함수는 부동 소수점을 올림해서 반환하는 함수

  • ex#1 - SELECT CEIL(0.5); → 1
  • ex#2 - SELECT CEIL(0.1); → 1
  • ex#3 - SELECT CEIL(-1.3); → -1

My Answer. 

SELECT CEIL(AVG(Salary) - AVG(REPLACE(Salary, '0', '')))
FROM EMPLOYEES;

References. 

 

MYSQL - CEIL() 함수

무료로 사용할 수 있는 CMS 형 PHP 버드 패널, 테마, FTP 외 라이브러리 제공

www.habonyphp.com

 

Comments