HACKERRANK 9일차

U_in_joy·2022년 5월 30일
0

SQL

목록 보기
9/16
post-thumbnail

Top Earners

SELECT MAX(salary * months), 
COUNT(name) FROM Employee WHERE salary * months = MAX(salary * months)
FROM Employee;

이렇게 썼더니 오답... subquery를 썼다고 생각했지만, 그것은 나의 착각... 서칭을 해보자!

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

GROUP BY, ORDER BY, LIMIT을 사용한 코드

SELECT salary * months AS earnings, COUNT(*)
FROM Employee
GROUP BY earnings
ORDER BY earnings DESC
LIMIT 1;
profile
끝까지 가자!

0개의 댓글