Top Competitors

  • + 0 comments

    (ms sql server)

    Can someone help me with my query, it returns only 20 rows as an output

    
    
    with cte_hacker_name(hacker_id, name, challenge_id, difficulty_level, score)
    as
    (
    select
        H.hacker_id, 
        H.name, 
        C.challenge_id, 
        C.difficulty_level,
        S.score 
    
    FROM 
        challenges AS C JOIN difficulty AS D ON C.difficulty_level = D.difficulty_level
        join submissions s on s.challenge_id = c.challenge_id
        join hackers H on H.hacker_id = C.hacker_id
    
    where 
        d.score= s.score
    )
    SELECT 
        hacker_id, name
    FROM 
        cte_hacker_name
    GROUP BY 
        hacker_id, name
    HAVING 
        COUNT(*) > 1
    ORDER BY 
        COUNT(*) DESC, hacker_id ASC;
    

    `