| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 31 |
Tags
- 알고리즘
- Hackerrank
- 정규표현식
- array
- 코드스테이츠
- select
- node.js
- Where
- Algorithms
- 역행자
- 자바스크립트
- Programmers
- 코딩테스트
- 개발자의 책장
- JavaScript
- for문
- 재귀함수
- 블록체인
- 코딩공부
- 최강의 인생
- array.push()
- MySQL
- 배열
- array.slice()
- join
- 개발자_조이킴
- Developer_JoyKim
- SQL
- 프로그래머스
- 코플릿
Archives
- Today
- Total
CodingSpace
[HackerRank/SQL] Revising Aggregations - Top Earners 본문
Problem. Revising Aggregations - Top Earners
Link.
The Blunder | HackerRank
Query the amount of error in Sam's result, rounded up to the next integer.
www.hackerrank.com
Description.
We define an employee's total earnings to be their monthly worked, and the maximum total earnings to be the maximum total earnings for any employee in the Employee table.
Write a query to find the maximum total earnings for all employees as well as the total number of employees who have maximum total earnings.
Then print these values as space-separated integers.


Key Point.
SELECT,
MAX,
COUNT,
IF,
Comments:
aiengr_talha님과 유사하게
SELECT
MAX(SALARY * MONTHS),
COUNT(IF(SALARY * MONTHS = MAX(SALARY * MONTHS), 1, null))
FROM Employee;
를 사용하려고 했음 (실제로 시도했지만, 원하는 데이터를 얻어올 수 없었음ㅠ)
- pyata_sandeep님의 답변을 참고하여 쿼리를 재작성함

My Answer.
SELECT
MAX(SALARY * MONTHS),
COUNT(IF(SALARY * MONTHS = (SELECT MAX(SALARY * MONTHS) FROM Employee), 1, null))
FROM Employee;
References.
'HackerRank > SQL' 카테고리의 다른 글
| [HackerRank/SQL] Basic Select - Weather Observation Station 12 (0) | 2022.07.20 |
|---|---|
| [HackerRank/SQL] Aggregation - Japan Population (0) | 2022.07.19 |
| [HackerRank/SQL] Revising Aggregations - The Blunder (0) | 2022.07.17 |
| [HackerRank/SQL] Revising Aggregations - Population Density Difference (0) | 2022.07.17 |
| [HackerRank/SQL] Revising Aggregations - Averages (0) | 2022.07.16 |
Comments