SQL
해커랭크(HackerRank) MySQL-Top Earners
potatode
2022. 8. 5. 11:08
SELECT *
FROM (
select salary*months as earning,
count(salary*months) as counting
from Employee
GROUP BY earning
) as salary
order by earning desc
limit 1
처음엔 이렇게 풀었다. 답은 나오지만 더 효율적인 코드는
select salary*months as earning, count(salary*months)
from Employee
where salary*months=(select max(salary*months) from Employee)
group by earning
select salary*months as earning, count(salary*months)
from Employee
group by earning
having earning=(select max(salary*months) from Employee)
✅ 예약어(SELECT, AND) 등은 대문자로 쓰는 습관을 가지자
반응형