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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. SQL
  3. Basic Join
  4. Challenges
  5. Discussions

Challenges

Problem
Submissions
Leaderboard
Discussions

Sort 1638 Discussions, By:

recency

Please Login in order to post a comment

  • aeesha2506
    5 hours ago+ 0 comments

    oracle my solution

    select a.hacker_id, h.name, a.cnt
    from (
    SELECT hacker_id,
                 COUNT (hacker_id)                                                  cnt,
                 MAX (COUNT (hacker_id)) OVER ()                                    mx,
                 COUNT (COUNT (hacker_id)) OVER (PARTITION BY COUNT (hacker_id))    rep_cnt
            FROM challenges
        GROUP BY hacker_id
        ) a join hackers h on (a.hacker_id = h.hacker_id)
    where not (rep_cnt>1 and cnt<mx)
    order by 3 desc, 1 asc
    ;
    
    0|
    Permalink
  • rajasanjaysingh1
    2 days ago+ 0 comments

    select total_base.hacker_id, total_base.name, total_base.total_challenges

    from (SELECT CASE WHEN ((identicals>1) AND (total_challenges

    where flag=0 ORDER BY total_base.total_challenges DESC, total_base.hacker_id ASC

    -1|
    Permalink
  • rajasanjaysingh1
    2 days ago+ 0 comments

    select total_base.hacker_id, total_base.name, total_base.total_challenges

    from (SELECT CASE WHEN ((identicals>1) AND (total_challenges

    where flag=0 ORDER BY total_base.total_challenges DESC, total_base.hacker_id ASC

    -3|
    Permalink
  • nhipham117
    2 days ago+ 0 comments

    MySQL

    WITH list_name AS(
        SELECT c.hacker_id, h.name, COUNT(c.challenge_id) AS challenges_created
        FROM Hackers h
        JOIN Challenges c ON h.hacker_id = c.hacker_id
        GROUP BY c.hacker_id, h.name
        ORDER BY COUNT(c.challenge_id) DESC, c.hacker_id),
        count_challenges AS(
        SELECT challenges_created, COUNT(challenges_created) AS counter
        FROM list_name
        GROUP BY challenges_created
        HAVING COUNT(challenges_created) = 1)
    SELECT
        list_name.hacker_id,
        list_name.name,
        list_name.challenges_created
    FROM list_name
    WHERE list_name.challenges_created = (SELECT MAX(challenges_created) FROM list_name)
        OR list_name.challenges_created IN (SELECT count_challenges.challenges_created FROM count_challenges);
    
    0|
    Permalink
  • mdevasish
    5 days ago+ 0 comments

    Easy to understand :

    with cte_1 as (select c.hacker_id,h.name,count(c.challenge_id) as cnt from challenges as c inner join hackers as h on c.hacker_id = h.hacker_id group by c.hacker_id,h.name order by cnt desc, c.hacker_id), cte_2 as ( select cnt,count(cnt) as count_count from cte_1 group by cnt having count_count = 1 or cnt = (select max(cnt) from cte_1) order by cnt desc)

    select cte_1.hacker_id, cte_1.name, cte_1.cnt from cte_1 inner join cte_2 on cte_1.cnt = cte_2.cnt

    0|
    Permalink
Load more conversations

Need Help?


View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy