BananMoon / SQL-Practice

It is Study Place to practice SQL.
0 stars 0 forks source link

Group By + HackerRank 문제풀이 #2

Open BananMoon opened 1 month ago

BananMoon commented 1 month ago

Group By

BananMoon commented 1 month ago
  1. Top Earners

해결 방법

문제를 읽어보면 아래 내용들로 SQL을 작성해야 한다.

  1. salary * month = earnings -> 사칙연산
  2. 각 earning 별로 그룹핑해서 몇 명이 그만큼 벌었는지 계산 -> group by
  3. earning 중에 가장 큰 값을 가져온다 -> order by & limit

SQL문

MySQL

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