728x90

문제: 모든 직원의 최대 총 수입과 최대 총 수입을 가진 직원의 총 수를 찾아라.
SELECT months * salary, COUNT(*)
FROM Employee
group by months * salary
order by months * salary desc
limit 1;
서브쿼리를 사용한 방법
SELECT MAX(months * salary), COUNT(*)
FROM Employee
WHERE (months * salary) = (SELECT MAX(months * salary) FROM Employee);
select salary*months, count(*) from employee
where salary*months = (select max(salary*months)from employee)
group by salary*months
select salary*months as a, count(*) from employee
group by a
having a = (select max(salary*months) from employee)

'SQL 공부' 카테고리의 다른 글
| LeetCode 로 공부하기 672. Swap Salary (1) | 2023.12.26 |
|---|---|
| HackerRank로 SQL 공부하기 - Weather Observation Station 15 (1) | 2023.12.23 |
| HackerRank로 SQL 공부하기 - The Blunder (1) | 2023.12.23 |
| HackerRank로 SQL 공부하기 - Average Population (0) | 2023.12.18 |
| HackerRank로 SQL 공부하기 advanced select - The PADS (0) | 2023.12.16 |