Growth ๐ŸŒณ/Practice ๐Ÿ’ป

[Hacker Rank] Top Competitors

์ธ” 2022. 8. 27. 01:16

๐Ÿ“ข ๋ณธ ํฌ์ŠคํŒ…์— ํ™œ์šฉ๋˜๋Š” ๊ธฐ๋ณธ ๋ฌธ์ œ ๋ฐ ์ž๋ฃŒ ์ถœ์ฒ˜๋Š” HackerRank ์ž„์„ ๋ฐํž™๋‹ˆ๋‹ค.

https://www.hackerrank.com


โ–  ๋ฌธ์ œ

https://www.hackerrank.com/challenges/full-score/problem

 

Top Competitors | HackerRank

Query a list of top-scoring hackers.

www.hackerrank.com

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. 


 

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๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ์ฟผ๋ฆฌ๋ฅผ ์ž‘์„ฑ

ํ•ด์ปค์˜ id์™€ ์ด๋ฆ„์œผ๋กœ ๊ทธ๋ฃนํ•‘์ด ํ•„์š”ํ•จ

> Submission์˜ score์™€ Difficulty์˜ score๊ฐ€ ๋™์ผํ•ด์•ผํ•จ.

> HAVING COUNT(Sub.submission_id) >= 2

 

ํ•ด์ปค๊ฐ€ ์ „์ฒด ์ ์ˆ˜๋ฅผ ํš๋“ํ•œ ์ด ์ฑŒ๋ฆฐ์ง€ ์ˆ˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ถœ๋ ฅ์„ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ

๋‘ ๋ช… ์ด์ƒ์˜ ํ•ด์ปค๊ฐ€ ๋™์ผํ•œ ์ˆ˜์˜ ์ฑŒ๋ฆฐ์ง€์—์„œ ์ „์ฒด ์ ์ˆ˜๋ฅผ ๋ฐ›์€ ๊ฒฝ์šฐ ํ•ด์ปค ID ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ

> ORDER BY COUNT(Sub.submission_id) DESC, H.hacker_id;

SELECT H.hacker_id  
      ,H.name
 FROM Submissions Sub

 INNER JOIN Hackers H
 ON Sub.hacker_id = H.hacker_id

 INNER JOIN Challenges C
 ON Sub.challenge_id = C.challenge_id

 INNER JOIN Difficulty D
 ON C.difficulty_level = D.difficulty_level

 WHERE Sub.Score = D.score
 GROUP BY 1, 2
 HAVING COUNT(Sub.submission_id) >= 2
 ORDER BY COUNT(Sub.submission_id) DESC, H.hacker_id;

 

 

'Growth ๐ŸŒณ > Practice ๐Ÿ’ป' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[๊ณผ์ œ] Pythob2022 #03 ์—ฐ์Šต๋ฌธ์ œ  (0) 2022.08.27
[Hacker Rank] Placement  (0) 2022.08.27
[Hacker Rank] Ollivander's Inventory  (0) 2022.08.26
[LeetCode] 176. Second Highest Salary  (0) 2022.08.26
[LeetCode] 1179. Reformat Department Table  (0) 2022.08.26