SQL & DB/HackerRank SQL Problem

[HackerRank SQL] Top Earners

YSY^ 2021. 2. 27. 18:30

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:

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

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

728x90
반응형