코딩테스트연습(SQL)
Top Earners / HackerRank, SQL, MySQL
LearnerToRunner
2022. 12. 15. 19:02
문제
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 space-separated integers.
제출답안(MySQL)
SELECT CONCAT(MAX(te.total_earning),' ', COUNT(te.employee_id))
FROM (SELECT months*salary AS total_earning, employee_id
FROM employee
WHERE months*salary = (SELECT MAX(months*salary) FROM employee)
) AS te
문제 바로가기(MySQL)
728x90