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
- Top Competitors
- Discussions
Top Competitors
Top Competitors
Sort by
recency
|
2519 Discussions
|
Please Login in order to post a comment
my sql : SELECT aaa.hacker_id, b.name FROM ( SELECT a.hacker_id, COUNT(DISTINCT a.challenge_id) AS totchal FROM submissions a LEFT JOIN challenges b ON a.challenge_id = b.challenge_id LEFT JOIN difficulty c ON b.difficulty_level = c.difficulty_level WHERE a.score = c.score GROUP BY a.hacker_id ) aaa LEFT JOIN hackers b ON aaa.hacker_id = b.hacker_id WHERE totchal > 1 ORDER BY totchal DESC, aaa.hacker_id ASC;
with cte as ( select
c.challenge_id, c.difficulty_level, d.score as top_score from challenges c join difficulty d on c.difficulty_level = d.difficulty_level ), cte2 as( select s.hacker_id, s.challenge_id, s.score from submissions s inner join cte c on s.challenge_id = c.challenge_id and s.score = c.top_score ) select h.hacker_id, h.name from cte2 c join hackers h on c.hacker_id = h.hacker_id group by h.hacker_id, h.name having count(c.challenge_id) > 1 order by count(c.challenge_id) desc, hacker_id asc
why is this wrong:
select h.hacker_id, h.name from Hackers h where count(*) from ( select s.hacker_id from submissions s join challenges c on c.challenge_id = s.challenge_id join difficulty d on d.difficulty_level = c.difficulty_level where d.score = s.score group by hacker_id, challenge_id )