문제 풀이 링크: 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
💰 Top Earners 문제 요약
- Employee 테이블에서
- 각 직원의 총 수입(total earnings) = salary * months
- 그 중 최고 총 수입(max total earnings)을 구하고
- 그 최고 수입을 받은 직원 수도 함께 구하기
- 결과는 공백으로 구분된 두 개의 숫자로 출력
정답 풀이
- WHERE 절에서 salary * months가 최댓값인 직원만 필터링하여 해당 총수입을 가진 직원 수를 세고 최대 총수입을 함께 출력
SELECT
MAX(salary * months) AS max_total_earnings,
COUNT(*) AS employee_count
FROM Employee
WHERE salary * months = (
SELECT MAX(salary * months) FROM Employee
);
'SQL' 카테고리의 다른 글
Draw The Triangle1, 2 (0) | 2025.05.05 |
---|---|
The Blunder (0) | 2025.05.05 |
Repeated Payments: Stripe SQL Interview Question (0) | 2025.05.03 |
Card Launch Success: JPMorgan SQL Interview Question (0) | 2025.05.03 |
Department vs. Company Salary: FAANG SQL Interview Question (0) | 2025.04.30 |