- Today
- Total
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 깃
- MySQL
- 컴퓨터통신
- 프로그래머스
- 행렬
- HackerRank
- NumPy
- pre-course
- npm install -g yarn 에러
- inner join
- TabNet
- 역전파
- 컴퓨터 통신
- map
- ERROR: install is not COMMAND nor fully qualified CLASSNAME.
- 딥러닝 개요
- 부스트캠프
- gpt-api에러
- 딥러닝 역사
- gpt-api
- pandas
- yarn 설치 에러
- 쉽게 배우는 데이터 통신과 컴퓨터 네트워크
- 프로그래머스 SQL
- python
- sql
- 연관분석
- 부스트캠프ai
- 쉽게 배우는 데이터 통신과 컴퓨터 네트워크 답지
- 코딩테스트
최말짱 블로그
[HackerRank]Top Competitors(mysql풀이) 본문
https://www.hackerrank.com/challenges/full-score/problem?isFullScreen=true
Top Competitors | HackerRank
Query a list of top-scoring hackers.
www.hackerrank.com
Julia just finished conducting a coding contest, and she needs your help assembling the leaderboard! Write a query to print the respective hacker_id and name of hackers who achieved full scores for more than one challenge. Order your output in descending order by the total number of challenges in which the hacker earned a full score. If more than one hacker received full scores in same number of challenges, then sort them by ascending hacker_id.
Hackers, Difficulty, Challenges, Submissions 총 4개의 테이블이 있다.
레벨 별 코딩테스트 만점 기준(Challenges table)을 참고하여 만점을 2번이상 받은 참가자의 hacker_id와 name을 출력하는 문제
주의
참가자의 만점의 갯수만큼 정렬해주고 갯수가 같을 경우 hacker_id로 정렬
<정답>
select h.hacker_id, h.name
from submissions s
inner join challenges c on c.challenge_id = s.challenge_id
inner join difficulty d on d.difficulty_level = c.difficulty_level
inner join hackers h on h.hacker_id = s.hacker_id
where c.difficulty_level = d.difficulty_level and s.score = d.score
group by h.hacker_id, h.name
having count(h.hacker_id)>1
order by count(h.hacker_id) desc, h.hacker_id ;
처음엔 where절을 이용하여 암묵적인 join방법으로 구성하려 하였으나 왠지모르게 실패.. 그래서 아둥바둥 하다가 결국 inner join을 여러번 써서 해결하였다. (오히려 명시적이라서 좋은 것 같다.)
알게된 것
1. order절에도 count()를 활용할 수 있다.
2. 테이블이 많아도 join만 하면 간단한 문제이니 겁먹지 말자 !
'HackerRank SQL' 카테고리의 다른 글
[프로그래머스]식품분류별 가장 비싼 식품의 정보 조회하기(MYSQL풀이) (0) | 2023.03.01 |
---|---|
[프로그래머스]조건에 맞는 도서와 저자 리스트 출력하기(mysql풀이) (0) | 2023.02.24 |
[프로그래머스]입양 시각 구하기(2)(mysql풀이) (0) | 2023.02.24 |
[HackerRank] The Report(mysql풀이) (0) | 2022.07.10 |