www.hackerrank.com/challenges/earnings-of-employees/problem
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
반응형
'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 |