www.hackerrank.com/challenges/earnings-of-employees/problem
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 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.
Input Format
The Employee table containing employee data for a company is described as follows:
![[HackerRank SQL] Top Earners 0](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
where employee_id is an employee's ID number, name is their name, months is the total number of months they've been working for the company, and salary is the their monthly salary.
Sample Input
![[HackerRank SQL] Top Earners 1](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
Sample Output
69952 1
Answer
select (salary*months) as earnings, count(*) # employee's total earnings to be their monthly
from employee
group by earnings
order by earnings desc
limit 1 # maximum total earning
Result
![[HackerRank SQL] Top Earners 2](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
'SQL & DB > HackerRank SQL Problem' 카테고리의 다른 글
[HackerRank SQL] Weather Observation Station 15, 16(MySQL) (0) | 2021.03.01 |
---|---|
[HackerRank SQL] Weather Observation Station 13, 14(MySQL) (0) | 2021.03.01 |
[HackerRank SQL] The Blunder (0) | 2021.02.27 |
[HackerRank SQL] New Companies (MySQL) (0) | 2021.02.27 |
[HackerRank SQL] Binary Tree Nodes (0) | 2021.02.27 |