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.
풀이
제출한 답
select salary * months as earnings, count(*)
from employee
where salary * months = (select max(salary * months) from employee)
group by earnings
-> where 절 서브쿼리 사용(집계함수 max 값이 하나이므로)
다른 답
select (months * salary) earnings, count(employee_id)
from employee
group by earnings
having earnings = (select max(months * salary) from employee)
-> having 절 사용하여 조건 부여
'데이터 분석 > SQL 연습문제' 카테고리의 다른 글
Challenges (HackerRank) (0) | 2022.09.19 |
---|---|
184. Department Highest Salary (LeetCode) (0) | 2022.09.18 |
196. Delete Duplicate Emails (LeetCode) (0) | 2022.09.16 |
627. Swap Salary (LeetCode) (0) | 2022.09.15 |
코테 연습 26일차 (프로그래머스 SQL 고득점 Kit) (0) | 2022.03.09 |
댓글