[Hacker Rank_MySQL]문제 풀이#Top Earners 본문

IT/코테문제

[Hacker Rank_MySQL]문제 풀이#Top Earners

호랑구야 2022. 2. 28. 09:00

SQL > Aggregation > Top Earners

 

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 * 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.

빨간 글씨는 내가 문제를 풀 때 중요하다고 생각한 부분이다.

 

SELECT MAX(SALARY * MONTHS), COUNT(*)
FROM EMPLOYEE
WHERE SALARY * MONTHS = (SELECT MAX(SALARY * MONTHS) FROM EMPLOYEE)

아래는 디스커션에서 참고한 내용으로, 순서대로 나열해서 한 개만 택하는 방식이다.

SELECT (SALARY * MONTHS) AS earnings, COUNT(*)
FROM EMPLOYEE
GROUP BY earnings
ORDER BY earnings DESC
LIMIT 1
반응형
Comments