Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- RLIKE
- sql
- 선형 모형
- mysql
- HTML
- L1정규화
- hackerrank
- 편향-분산 교환
- branch
- AWS
- 버전충돌
- programmers
- merge
- early stopping
- github
- 클라우드컴퓨팅
- window function
- 깃헙협업
- CSS
- elastic net
- 교차 엔트로피
- 코딩공부
- PYTHON
- conflict
- Git
- 온라인협업
- coding
- full request
- leetcode
- L2정규화
Archives
- Today
- Total
Im between cherry
Hackerrank | MySQL | Top Earners 본문
Top Earners
Top Earners | HackerRank
Find the maximum amount of money earned by any employee, as well as the number of top earners (people who have earned this amount).
www.hackerrank.com
We define an employee's total earnings to be their monthly salaryXmonths 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 2 space-separated integers.
where employee_id is an employee's ID number, name is their name, months is the total number of months they've been working for the company, and salary is the their monthly salary.
-- Having절 서브쿼리를 이용한 풀이
SELECT months * salary AS earnings
, COUNT(*)
FROM employee
GROUP BY earnings
HAVING earnings = (SELECT MAX(months*salary) FROM employee)
-- WHERE절 서브쿼리를 이용한 풀이
SELECT months * salary AS earnings
, COUNT(*)
FROM employee
--highest earnings
WHERE months * salary = (SELECT MAX(months*salary) FROM employee)
GROUP BY earnings
'데이터분석 > practice_query' 카테고리의 다른 글
Hackerrank | MySQL | Weather Observation Station 13 (0) | 2020.08.29 |
---|---|
Hackerrank | MySQL | Weather Observation Station 2 (0) | 2020.08.29 |
Hackerrank | MySQL | The Blunder (0) | 2020.08.28 |
Hackerrank | MySQL | Population Density Difference (0) | 2020.08.28 |
Hackerrank | MySQL | Japan Population (0) | 2020.08.28 |
Comments