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 | 29 | 30 |
Tags
- 클라우드컴퓨팅
- HTML
- Git
- 온라인협업
- L2정규화
- 버전충돌
- programmers
- 코딩공부
- elastic net
- mysql
- window function
- branch
- PYTHON
- hackerrank
- RLIKE
- full request
- AWS
- 교차 엔트로피
- CSS
- github
- leetcode
- sql
- 선형 모형
- merge
- L1정규화
- conflict
- early stopping
- 깃헙협업
- coding
- 편향-분산 교환
Archives
- Today
- Total
Im between cherry
Hackerrank | MySQL | Top Earners 본문
Top Earners
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