[SQL] [백문이불여일타] 데이터 분석을 위한 중급 SQL-GROUP BY & HAVING 문제 풀이

한예은·2025년 2월 23일
0

코딩 테스트

목록 보기
3/49
post-thumbnail

후기

문제를 풀다가 자꾸 오답이라길래 왜 그런지 문제를 다시 읽어 보니 발견!
the total number of employees who have maximum total earnings를 구하려면 limit를 걸어야 하는데 걸지 않은 것 때문에 오답이었던 것이다.
연봉 높은 순으로 내림차순하면 되지 -> 가장 높은 연봉을 받는 사람들은 자연스럽게 맨 위에 뜰 테니까 (구했다!)라고 생각한 나의 잘못;_;
초중고 내내 문제를 마음대로 읽고 풀어 놓친 점수와 등급이 다시금 떠올랐다.
이렇게 쉬운 문제도 제대로 읽지 않으면 다 알고서도 틀린다.
문제를 제대로 읽자!

Top Earners

We define an employee's total earnings to be their monthly worked, and the maximum total earnings to be the maximum total earnings for any employee in the Employee table. Write a query to find the maximum total earnings for all employees as well as the total number of employees who have maximum total earnings. Then print these values as space-separated integers.

Input Format

The Employee table containing employee data for a company is described as follows:

풀이

select months * salary as earnings, count(*)
from employee
group by earnings
order by earnings desc
limit 1
profile
긴 여정의 첫 걸음

0개의 댓글