일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- join
- Round
- 그로스해킹
- 결측값
- not in
- 데이터분석
- 데이터시각화
- airflow.cfg
- 다중 JOIN
- SQLite
- Limit
- SQL
- MySQL
- PostgreSQL
- GROUPBY
- 데이터리안 웨비나
- Oracle
- SUM
- pandas
- 파이썬
- 프로그래머스
- TRUNCATE
- having
- 머신러닝
- solvesql
- hackerrank
- matplotlib
- airflow 설치
- 전처리
- seaborn
- Today
- Total
Milky's note
[HackerRank](E) The Blunder 본문
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
[문제]
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.
Input Format
The EMPLOYEES table is described as follows:

Note: Salary is per month.
[답]
-mysql
select ceil(avg(salary) - avg(replace(salary,0,''))) from EMPLOYEES
문제가 엄청 긴데, 결국 지금 급여의 평균에서 0을 제거한 급여의 평균을 뺀 값에 올림 처리를 해주면 된다.
여기에서 헷갈리는 점이 있는데 앞에는 반올림을 하여라였고 지금은 무조건 올림을 하는 조건이다.
그래서 ceil을 사용해주었다. 문제에서 숫자 처리 부분을 잘 읽어야겠다.
- ceil : 올림 (숫자)
- round : 반올림 (숫자, (나타낼 소수점 뒤 자리수))
- truncate : 버림 (숫자, 자리수)
'SQL > SQL 코딩 테스트-HackerRank' 카테고리의 다른 글
[HackerRank](E) Weather Observation Station 2 (0) | 2022.03.25 |
---|---|
[HackerRank](E) Top Earners (0) | 2022.03.25 |
[HackerRank](E) Population Density Difference (0) | 2022.03.25 |
[HackerRank](E) Japan Population (0) | 2022.03.25 |
[HackerRank](E) Average Population (0) | 2022.03.25 |