15 Days of Learning SQL Hacker Rank Solution

Hello coders, In this post, you will learn how to solve the 15 Days of Learning SQL Hacker Rank Solution. This problem is a part of the SQL Hacker Rank series.

We also provide Hackerrank solutions in CC++Java programming, and Python Programming languages so whatever your domain we will give you an answer in your field.

You can practice and submit all HackerRank problem solutions in one place. Find a solution for other domains and Sub-domain. I.e. Hacker Rank solution for HackerRank C ProgrammingHackerRank C++ ProgrammingHackerRank Java Programming, HackerRank Python ProgrammingHackerRank Linux ShellHackerRank SQL Programming, and HackerRank 10 days of Javascript.

15 Days of Learning SQL Hacker Rank Solution
15 Days of Learning SQL Hacker Rank Solution

As you already know that this site does not contain only the Hacker Rank solutions here, you can also find the solution for other problems. I.e. Web Technology, Data StructuresRDBMS ProgramsJava Programs Solutions,  Fiverr Skills Test answersGoogle Course AnswersLinkedin Assessment, and Coursera Quiz Answers.

15 Days of Learning SQL Hacker Rank Solution


Julia conducted a  days of learning SQL contest. The start date of the contest was March 01, 2016 and the end date was March 15, 2016.

Write a query to print total number of unique hackers who made at least  submission each day (starting on the first day of the contest), and find the hacker_id and name of the hacker who made maximum number of submissions each day. If more than one such hacker has a maximum number of submissions, print the lowest hacker_id. The query should print this information for each day of the contest, sorted by the date.

Input Format

The following tables hold contest data:

  • Hackers: The hacker_id is the id of the hacker, and name is the name of the hacker.
  • Submissions: The submission_date is the date of the submission, submission_id is the id of the submission, hacker_id is the id of the hacker who made the submission, and score is the score of the submission. 

Sample Input

For the following sample input, assume that the end date of the contest was March 06, 2016.

Hackers Table:  Submissions Table: 

Sample Output

2016-03-01 4 20703 Angela
2016-03-02 2 79722 Michael
2016-03-03 2 20703 Angela
2016-03-04 2 20703 Angela
2016-03-05 1 36396 Frank
2016-03-06 1 20703 Angela

15 Days of Learning SQL Hacker Rank Solution

SELECT t1.submission_date, hkr_cnt, t2.hacker_id, name
FROM (SELECT p1.submission_date,
             COUNT(DISTINCT p1.hacker_id) AS hkr_cnt
      FROM (SELECT submission_date, hacker_id,
                   @h_rnk := CASE WHEN @h_grp != hacker_id THEN 1 ELSE @h_rnk+1 END AS hacker_rank,
                   @h_grp := hacker_id AS hacker_group
            FROM (SELECT DISTINCT submission_date, hacker_id
                  FROM submissions
                  ORDER BY hacker_id, submission_date) AS a,
                 (SELECT @h_rnk := 1, @h_grp := 0) AS r) AS p1
      JOIN (SELECT submission_date,
                   @d_rnk := @d_rnk + 1 AS date_rank
            FROM (SELECT DISTINCT submission_date
                  FROM submissions
                  ORDER BY submission_date) AS b,
                 (SELECT @d_rnk := 0) r) AS p2
      ON p1.submission_date = p2.submission_date
         AND hacker_rank = date_rank
      GROUP BY p1.submission_Date) AS t1
JOIN (SELECT submission_date, hacker_id, sub_cnt,
             @s_rnk := CASE WHEN @d_grp != submission_date THEN 1 ELSE @s_rnk+1 END AS max_rnk,
             @d_grp := submission_date AS date_group
      FROM (SELECT submission_date, hacker_id, COUNT(*) AS sub_cnt
            FROM submissions AS s
            GROUP BY submission_date, hacker_id
            ORDER BY submission_date, sub_cnt DESC, hacker_id) AS c,
           (SELECT @s_rnk := 1, @d_grp := 0) AS r) AS t2
ON t1.submission_date = t2.submission_date AND max_rnk = 1
JOIN hackers AS h ON h.hacker_id = t2.hacker_id
ORDER BY t1.submission_date

Disclaimer: The above Problem (15 Days of Learning SQL) generated by Hackerrank but the Solution is Provided by Chase2Learn. This tutorial is only for Educational and Learning purposes. Authority if any of the queries regarding this post or website fill the following contact form thank you.


Is HackerRank good for SQL practice?

You’ve probably heard of HackerRank before, so it should be no surprise to you that they have one of the best collections of SQL practice challenges around.

Which SQL does HackerRank use?

The HackerRank Test interface has an in-built database query editor and supports programming in Microsoft SQL, MySQL, Oracle, or DB2 databases.

What is HackerRank SQL?

Basic. Get Certificate. SQL is an industry-standard query language that works with relational databases. Unlike some earlier systems, queries are performed at the server and only the results are passed to a client. This resulted in the ability to work with large databases efficiently over a network. 

How many questions are there in HackerRank for SQL?

That will also help your SQL code challenges journey

It took me a bit more than two weeks (on and off between work, workout, and taking the kid to day school, etc.) to finish all the 58 SQL challenges on the site, and I gained quite some insights from the journey (and having quite some fun doing that!).

Where can I find HackerRank solutions in SQL?

in this post, you will get all the solutions of HackerRank SQL Problems.


Finally, we are now, in the end, I just want to conclude some important message for you

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Please share our posts on social media platforms and also suggest to your friends to Join Our Groups. Don’t forget to subscribe. 

We Have Covered Hackerrank SQL all question answers :

hackerrank,hackerrank sql solutions,hackerrank sql,hackerrank solutions,hackerrank solution,sql solution,revising the select query in hackerrank solution,sql solutions hackerrank,hacker rank solutins of sql,hackerrank certificate solutions,select all hackerrank solution,hackerrank the pads solution in hindi,weather observation station 3 hackerrank solution,weather observation station 4 hackerrank solution,weather observation station 7 hackerrank solution

Sharing Is Caring

Leave a Comment