DB/SQL오답노트

[DB/SQL오답노트] HackerRank Top Competitors

2023. 8. 14. 08:34

1.문제

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.


Input Format

The following tables contain contest data:

  • Hackers: The hacker_id is the id of the hacker, and name is the name of the hacker.
  • Difficulty: The difficult_level is the level of difficulty of the challenge, and score is the score of the challenge for the difficulty level.
  • Challenges: The challenge_id is the id of the challenge, the hacker_id is the id of the hacker who created the challenge, and difficulty_level is the level of difficulty of the challenge.
  • Submissions: The submission_id is the id of the submission, hacker_id is the id of the hacker who made the submission, challenge_id is the id of the challenge that the submission belongs to, and score is the score of the submission.

Sample Input

Hackers Table:

Difficulty Table:

Challenges Table:

Submissions Table:

Sample Output

90411 Joe

Explanation

Hacker 86870 got a score of 30 for challenge 71055 with a difficulty level of 2, so 86870 earned a full score for this challenge.

Hacker 90411 got a score of 30 for challenge 71055 with a difficulty level of 2, so 90411 earned a full score for this challenge.

Hacker 90411 got a score of 100 for challenge 66730 with a difficulty level of 6, so 90411 earned a full score for this challenge.

Only hacker 90411 managed to earn a full score for more than one challenge, so we print the their hacker_id and name as  space-separated values.

 

2.구해야 하는 것

2-1. Full score(만점)을 받은 챌린지가 2개 이상인 참가자를 찾아야한다.

2-2. 만점이란, Submission 테이블의 score값과 Difficulty 테이블의 score값이 일치하는 걸 의미한다.

2-3. 문제에서 제시한 2가지 정렬 기준을 만족시키기

 

3.정답

SELECT H.hacker_id, H.name
FROM Submission S
    INNER JOIN Challenges C ON S.challenge_id = C.challenge_id
    INNER JOIN Difficulty D ON C.difficulty_level = D.difficult_level
    INNER JOIN Hackers H ON S.hacker_id = H.hacker_id
WHERE S.score = D.score AND C.difficulty_level = D.difficulty_level
GROUP BY H.hacker_id, H.name
HAVING COUNT(H.hacker_id)> 1
ORDER BY COUNT(H.hacker_id) DESC, H.hacker_id

 

'DB > SQL오답노트' 카테고리의 다른 글

[DB/SQL오답노트/HackerRank] Average Population of Each Continent  (0) 2023.08.10
[SQL/SQL오답노트]LV2.가격대 별 상품 개수 구하기  (0) 2023.05.16
[SQL/SQL오답노트]LV4.우유와 요거트가 담긴 장바구니  (0) 2023.04.13
[SQL/SQL오답노트]LV3.대여 횟수가 많은 자동차들의 월별 대여 횟수 구하기  (0) 2023.04.12
[SQL/SQL오답노트]LV4.서울에 위치한 식당 목록 출력하기  (0) 2023.04.06
'DB/SQL오답노트' 카테고리의 다른 글
  • [DB/SQL오답노트/HackerRank] Average Population of Each Continent
  • [SQL/SQL오답노트]LV2.가격대 별 상품 개수 구하기
  • [SQL/SQL오답노트]LV4.우유와 요거트가 담긴 장바구니
  • [SQL/SQL오답노트]LV3.대여 횟수가 많은 자동차들의 월별 대여 횟수 구하기
각시탈코더
각시탈코더
각시탈코더
각시탈코더
각시탈코더
전체
오늘
어제
  • 분류 전체보기 (203)
    • java (46)
      • 객체지향 (20)
      • 기본문법 (8)
      • 자바의 정석 연습문제 오답노트 (9)
      • 백준 알고리즘 (9)
    • Spring (17)
      • SpringMVC (8)
      • Spring DI와 AOP (5)
      • REST API와 Ajax (1)
      • Spring 프로젝트 (1)
      • Spring Security (0)
    • DB (47)
      • Oracle (15)
      • SQL오답노트 (25)
      • 튜닝 (0)
      • ERD (1)
      • DB 모델링 (5)
    • Servlet & JSP (3)
    • JDBC (2)
      • 기본 (1)
      • 스프링JDBC (1)
    • MyBatis (2)
    • JavaScript (2)
      • 코딩애플 (0)
      • 문법 (1)
    • React (0)
      • 코딩애플 (0)
    • HTML (0)
      • 모던 웹을 위한 HTML5+CSS3 바이블 (0)
    • CSS (0)
      • 모던 웹을 위한 HTML5+CSS3 바이블 (0)
    • Linux (0)
    • Git & GitHub (2)
      • Git (1)
    • CS (19)
      • 네트워크 (6)
      • HTTP (7)
      • 컴퓨터구조 (0)
      • 자료구조와 알고리즘 (2)
      • 기타 (4)
    • 개발설정 (2)
    • 기술면접 (0)
      • JAVA (0)
      • Spring (0)
      • DB (0)
      • 네트워크 (0)
      • 공통 (0)
    • 프로젝트 (2)
      • 게시판만들기 (2)
    • 기혁씨의 삽질표류기 (28)
    • 참고자료 (2)
      • 국비수업 (0)
      • 당당 프로젝트 (1)
    • 뉴렉처 (17)
      • 자바 (11)
      • 자바스크립트 (3)
      • 키워드 (0)
      • 숙제 (0)
      • CSS (0)
      • DB (3)
      • 서블릿 (0)
      • 스프링 (0)
      • DOM (0)
    • 내가 만든 학습그림 (3)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • Oracle
  • 백엔드
  • SQL
  • 연습문제
  • 서브쿼리
  • 오라클
  • It
  • 에러
  • spring
  • 웹프로그래밍
  • 자바의정석
  • 오류
  • 객체지향
  • 스프링
  • 자바
  • Java
  • 공부
  • 모두의네트워크
  • 프로그래머스
  • 네트워크
  • 백준
  • 쿼리
  • 뉴렉처
  • 개발자
  • 자바의정석기초편
  • db
  • 국비수업
  • 알고리즘
  • 코딩
  • 배열

최근 댓글

최근 글

hELLO · Designed By 정상우.
각시탈코더
[DB/SQL오답노트] HackerRank Top Competitors
상단으로

티스토리툴바

개인정보

  • 티스토리 홈
  • 포럼
  • 로그인

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.