[mySQL] 해커랭크 Top Earners 3가지 풀이 방법

sehyunny·2023년 5월 9일
0

mySQL

목록 보기
9/26

https://www.hackerrank.com/challenges/earnings-of-employees/problem?h_r=internal-search

풀이 1. 제일 쉬운(?) 방법

SELECT salary * months AS earnings, COUNT(*)
FROM Employee
GROUP BY earnings
ORDER BY earnings DESC
LIMIT 1

풀이 2. WHERE 절 서브쿼리 활용

SELECT salary * months AS earnings, COUNT(*)
FROM Employee
WHERE salary * months = (SELECT MAX(salary * months) FROM Employee)
GROUP BY earnings

풀이 3. HAVING 절 서브쿼리 활용

SELECT salary * months AS earnings, COUNT(*)
FROM Employee
GROUP BY earnings
HAVING earnings = (SELECT MAX(salary * months) FROM Employee)

서브쿼리 어렵다...ㅠㅠ 흑흑

0개의 댓글