SQL

Top Earners

sawo11 2025. 5. 5. 02:43

문제 풀이 링크: 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
);