https://www.hackerrank.com/challenges/challenges/problem?isFullScreen=true
Challenges | HackerRank
Print the total number of challenges created by hackers.
www.hackerrank.com
Julia asked her students to create some coding challenges. Write a query to print the hacker_id, name, and the total number of challenges created by each student. Sort your results by the total number of challenges in descending order. If more than one student created the same number of challenges, then sort the result by hacker_id. If more than one student created the same number of challenges and the count is less than the maximum number of challenges created, then exclude those students from the result.
Input Format
The following tables contain challenge data:
WITH counter AS (
SELECT h.hacker_id,
h.name,
COUNT(*) challenges_created
FROM Challenges c
INNER JOIN Hackers h ON c.hacker_id = h.hacker_id
GROUP BY h.hacker_id, h.name
)
SELECT counter.hacker_id
counter.name,
counter.challenges_created
FROM counter
WHERE challenges_created = (SELECT MAX(challenges_created) FROM counter)
OR challenges_created IN (SELECT challenges_created
FROM counter
GROUP BY challenges_created
HAVING COUNT(*) = 1)
ORDER BY counter.challenges_created DESC, counter.hacker_id
with문으로 아이디, 이름, 생성한 문제의 개수를 표시하는 counter 테이블을 만들고 조건을 줘서 문제를 푼다.
Consecutive Numbers(LeetCode) (0) | 2022.08.05 |
---|---|
The Report(HackerRank) (0) | 2022.08.05 |
Department Highest Salary(Leet Code) (0) | 2022.08.05 |
Delete Duplicate Emails(Leet Code) (0) | 2022.08.02 |
Swap Salary(LeetCode) (0) | 2022.08.02 |
댓글 영역