문제 링크
https://www.hackerrank.com/challenges/earnings-of-employees/problem?isFullScreen=true
Top Earners | HackerRank
Find the maximum amount of money earned by any employee, as well as the number of top earners (people who have earned this amount).
www.hackerrank.com
문제
We define an employee's total earnings to be their monthly salary x months 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 2 space-separated integers.
직원의 총 수입은 월 급여 x (근무한)개월로 정의되며, 최대 총 수입은 Employee 테이블에 있는 모든 직원의 최대 총 수입으로 정의한다. 모든 직원의 최대 총 수입과 최대 총 수입을 가진 직원 수를 찾는 쿼리를 작성하시오. 그 다음, 이 값을 공백으로 구분된 2개의 정수로 인쇄하시오.
문제풀이
- 월 급여(SALARY) * 개월(MONTHS)를 EARNINGS로 정의한다.
- EARNINGS로 GROUP BY하고 내림차순으로 정렬한다.
- LIMIT 1을 통해 가장 위에 있는 행(최대 총 수입)과 최대 총 수입을 가진 직원수를 COUNT로 세준다.
쿼리문
SELECT SALARY * MONTHS AS EARNINGS, COUNT(*)
FROM EMPLOYEE
GROUP BY EARNINGS
ORDER BY EARNINGS DESC
LIMIT 1;
'SQL > HackerRank(MYSQL)' 카테고리의 다른 글
[SQL][HackerRank] The Blunder (0) | 2022.04.18 |
---|---|
[SQL][HackerRank] Type of Triangle (0) | 2022.04.13 |
MySQL 설치 및 환경 구축 (4-1) - MySQL설치 후 Workbench로 접속하기 (0) | 2021.01.12 |
MySQL 설치 및 환경 구축 (2, 3) - MySQL 설치 및 구동 (0) | 2020.12.30 |
MySQL 설치 및 환경 구축 (1) - 리눅스용 윈도우 하위 시스템(WSL) 설치 (0) | 2020.12.30 |