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 | 31 |
Tags
- SKU Consolidation
- 신경쓰기의 기술
- ABC Analysis
- tensorflow
- Labor Management System
- 피그마인디언
- 데이터분석
- Inventory Optimization
- leetcode
- HackerRank
- 당신의 인생이 왜 힘들지 않아야 한다고 생각하십니까
- ProfileReport
- MySQL
- Product Demand
- 파이썬
- kaggle
- 프로그래머스
- 코딩테스트연습
- ModelCheckPoint
- MS SQL Server
- pandas profiling
- SQL
- forecast
- oracle
- 코딩테스트
- 웨어하우스 보관 최적화
- 딥러닝
- eda
- TensorFlowGPU
- Gaimification
Archives
- Today
- Total
오늘도 배운다
Contest Leaderboard / HackerRank SQL MySQL 본문
문제
source: HackerRank
You did such a great job helping Julia with her last coding contest challenge that she wants you to work on this one, too!
The total score of a hacker is the sum of their maximum scores for all of the challenges. Write a query to print the hacker_id, name, and total score of the hackers ordered by the descending score. If more than one hacker achieved the same total score, then sort the result by ascending hacker_id. Exclude all hackers with a total score of () from your result.
제출답안(MySQL)
SELECT hacker_id, name, SUM(max_score) AS total_score
FROM
( SELECT s.hacker_id, h.name, s.challenge_id, MAX(s.score) as max_score
FROM submissions AS s JOIN hackers AS h ON s.hacker_id = h.hacker_id
GROUP BY hacker_id, name, challenge_id
) j_sh
GROUP BY hacker_id, name
HAVING total_score > 0
ORDER BY 3 DESC, 1
풀이(MySQL)
더보기
최종적으로 join 한 테이블에서 hacker_id, name, 각 챌린지의 최대 점수 합을 조회
SELECT hacker_id, name, SUM(max_score) AS total_score
submissions와 hackers 테이블 조인 후 최종쿼리에 필요한 정보 및 challenge 별 최고점수 조회
FROM
( SELECT s.hacker_id, h.name, s.challenge_id, MAX(s.score) as max_score
FROM submissions AS s JOIN hackers AS h ON s.hacker_id = h.hacker_id
GROUP BY hacker_id, name, challenge_id
) j_sh
해커의 id와 이름으로 그룹화
GROUP BY hacker_id, name
GROUP BY 결과에서 총 점수가 0점 넘는 데이터만 조회 및 정렬
HAVING total_score > 0
ORDER BY 3 DESC, 1
문제 바로가기(MySQL)
728x90
'코딩테스트연습(SQL)' 카테고리의 다른 글
Challenges / HackerRank, SQL, MySQL (0) | 2023.02.18 |
---|---|
Placements / HackerRank, SQL, MySQL (0) | 2023.02.17 |
Top Competitors / HackerRank, SQL, MySQL (0) | 2023.01.03 |
New Companies / HackerRank, SQL, MySQL (0) | 2023.01.03 |
The Report / HackerRank, SQL, MySQL (0) | 2022.12.28 |
Comments