We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- SQL
- Basic Join
- Challenges
- Discussions
Challenges
Challenges
Sort by
recency
|
2437 Discussions
|
Please Login in order to post a comment
SELECT c.hacker_id, h.name, count(c.challenge_id) AS cnt FROM Hackers AS h JOIN Challenges AS c ON h.hacker_id = c.hacker_id GROUP BY c.hacker_id, h.name HAVING cnt = (SELECT count(c1.challenge_id) FROM Challenges AS c1 GROUP BY c1.hacker_id ORDER BY count(*) desc limit 1) or cnt NOT IN (SELECT count(c2.challenge_id) FROM Challenges AS c2 GROUP BY c2.hacker_id HAVING c2.hacker_id <> c.hacker_id) ORDER BY cnt DESC, c.hacker_id;
with cte as ( select h.hacker_id,h.name,count(c.challenge_id) as no_of_challenges from hackers h join challenges c on h.hacker_id = c.hacker_id group by h.hacker_id,h.name order by count(c.challenge_id) desc,h.hacker_id asc ) select hacker_id,name,no_of_challenges from cte where no_of_challenges in (select no_of_challenges from cte group by no_of_challenges having (no_of_challenges>=50) or (count(*)<2 and no_of_challenges<50)); `
with cte1 as (select h.hacker_id as hacker_id, name, count(challenge_id) as challenge_created from hackers h join challenges c on h.hacker_id = c.hacker_id group by h.hacker_id, name order by challenge_created desc, hacker_id),
cte2 as ( select challenge_created, count(hacker_id) no_of_students from cte1 group by challenge_created)
select hacker_id, name, cte1.challenge_created #,no_of_students from cte1 join cte2 on cte1.challenge_created = cte2.challenge_created where cte1.challenge_created = (select max(challenge_created) from cte1) or no_of_students < 2;
WITH CTE1 AS ( SELECT HACKER_ID, COUNT(CHALLENGE_ID) AS CNT1 FROM CHALLENGES GROUP BY HACKER_ID ), CTE2 AS ( SELECT CNT1, COUNT(CNT1) AS CNT2 FROM CTE1 GROUP BY CNT1 HAVING CNT1 = (SELECT MAX(CNT1) FROM CTE1) OR COUNT(CNT1) = 1 ) SELECT C1.HACKER_ID,HC.NAME, C1.CNT1 FROM CTE1 C1 INNER JOIN CTE2 C2 ON C1.CNT1 = C2.CNT1 INNER JOIN HACKERS HC ON HC.HACKER_ID = C1.HACKER_ID ORDER BY C1.CNT1 DESC, C1.HACKER_ID ASC