Top earners - 서브쿼리
https://www.hackerrank.com/challenges/earnings-of-employees/problem
SELECT months*salary as earnings
, count(*)
FROM employee
WHERE months*salary = (SELECT MAX(months*salary) FROM employee)
GROUP BY earnings
-- Having >>> GROUP BY 결과물을 다시 한 번 필터링 해줄 때
SELECT months*salary AS earnings
, count(*)
FROM employee
GROUP BY earnings
HAVING earnings = (SELECT MAX(months*salary) FROM employee) -- 전체 임직원 중에서 최대 값을 가진 사람만
-- FROM >>> FROM 절을 테이블로 활용
SELECT *
FROM (
SELECT months*salary AS earnings
, count(*)
FROM employee
GROUP BY earnings
) sub
ORDER BY earnings DESC
limit 1;
'기존학습자료 > leetcode, hackerrank' 카테고리의 다른 글
해커랭크 - The Report (SELECT + CASE) (0) | 2023.06.25 |
---|---|
해커랭크 - Challenges (0) | 2023.06.25 |
서브쿼리 기초 (0) | 2023.06.24 |
Leetcode 180 - Consecutive Numbers (0) | 2023.06.24 |
Leetcode 1179 - Reformat Department Table (0) | 2023.06.24 |