Input Format
The following tables contain contest data:
-
Hackers:
-
Difficulty:
-
Challenges:
-
Submissions:
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.
아래의 조건으로 id와 이름 조회하기
- 챌린지에서 만점받은 수가 1개 이상
- 그 개수를 내림차순으로 + 동수일 경우 id 오름차순으로
SELECT
H.hacker_id,
H.name
FROM
Hackers AS H
INNER JOIN Submissions AS S
ON H.hacker_id = S.hacker_id
INNER JOIN Challenges AS C
ON S.challenge_id = C.challenge_id
INNER JOIN Difficulty AS D
ON C.difficulty_level = D.difficulty_level
WHERE
S.score = D.score
GROUP BY H.hacker_id, H.name
-- 그룹화의에 조건 달려면 HAVING 사용!
HAVING COUNT(*) > 1
ORDER BY COUNT(H.hacker_id) DESC, H.hacker_id ASC
'MYSQL 코테 준비' 카테고리의 다른 글
[HacKerRank SQL] SQL Project Planning - MYSQL (0) | 2021.03.09 |
---|---|
[HacKerRank SQL] Ollivander's Inventory - MYSQL (0) | 2021.02.25 |
[HacKerRank SQL] The Report - MYSQL (0) | 2021.02.24 |
[HacKerRank SQL] Asian Population- MYSQL (0) | 2021.02.24 |
[HacKerRank SQL] New Companies- MYSQL (0) | 2021.02.19 |
댓글