๐๋ณธ ํฌ์คํ
์์ ์ฌ์ฉ๋๋ ํ
์ด๋ธ์ ์๋ฃ์ ์ถ์ฒ๋ HackerRank ์์ ๋ฐํ๋๋ค.
https://www.hackerrank.com/challenges/full-score/problem?isFullScreen=false
๐๋ฌธ์ ํ์ด
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.
์ค๋ฆฌ์๋ ์ฝ๋ฉ ๋ํ๋ฅผ ๋ง์ณค๊ณ ์ฐธ๊ฐ์๋ค์ ์ ์ ๋ฆฌ๋๋ณด๋๋ฅผ ๋ง๋๋ ค๊ณ ํ๋ค. 2๊ฐ ์ด์์ Challenge(๋ฌธ์ )์์ Full score(๋ง์ )๋ฅผ ๋ฐ์ Hacker๋ค์ ์ด๋ฆ๊ณผ hacker_id๋ฅผ ์ถ๋ ฅํด๋ผ. ์ด ๋ ๊ฒฐ๊ณผ ํ๋ฉด์ Full score๋ฅผ ๋ฐ์ Challenge์ ๊ฐ์๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌํ๊ณ , ๋ง์ฝ Full score๋ฅผ ๋ฐ์ Challenge ๊ฐ์๊ฐ ๋์ผํ๋ค๋ฉด hacker_id ๋ฅผ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌํด๋ผ.
FROM Submissions S
INNER JOIN Challenges C ON S.challenge_id=C.challenge_id
INNER JOIN Difficulty D ON C.difficulty_level=D.difficulty_level
INNER JOIN Hackers H ON S.hacker_id=H.hacker_id
WHERE D.score=S.score AND D.difficulty_level=C.difficulty_level
SELECT H.hacker_id, H.name
FROM Submissions S
INNER JOIN Challenges C ON S.challenge_id=C.challenge_id
INNER JOIN Difficulty D ON C.difficulty_level=D.difficulty_level
INNER JOIN Hackers H ON S.hacker_id=H.hacker_id
WHERE D.score=S.score AND D.difficulty_level=C.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 ASC;
SELECT H.hacker_id, H.name
FROM Submissions S
INNER JOIN Challenges C ON S.challenge_id=C.challenge_id
INNER JOIN Difficulty D ON C.difficulty_level=D.difficulty_level
INNER JOIN Hackers H ON S.hacker_id=H.hacker_id
WHERE D.score=S.score AND D.difficulty_level=C.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 ASC;
๐๋ฌธ์ ํด๊ฒฐ์ ์ํ ์์ด๋์ด
1. full score๋ฅผ ๋ง์ ๋ฌธ์ ๊ฐ 2๊ฐ ์ด์์ธ ์ฐธ๊ฐ์๋ค์ ์์๋ณด๊ธฐ ์ํด hacker_id, name์ ๊ธฐ์ค์ผ๋ก groupingํ๊ณ , hacker_id๋ฅผ countํ๋ค.