일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 최강의 인생
- 블록체인
- Algorithms
- SQL
- 자바스크립트
- 프로그래머스
- 개발자의 책장
- Programmers
- 배열
- 정규표현식
- Where
- 역행자
- for문
- 알고리즘
- 코플릿
- 코딩공부
- 코드스테이츠
- JavaScript
- array
- array.slice()
- 개발자_조이킴
- select
- Hackerrank
- node.js
- join
- MySQL
- array.push()
- Developer_JoyKim
- 재귀함수
- 코딩테스트
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