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.
Your code throws an error, as h.name is not functionally dependent on the columns in the group by clause (h.name is not included in the group by clause) and to remove the redundancy just remove this condition, c.difficulty_level = d.difficulty_level. That should work. Here is my code, that worked fine for me,
SELECT H.HACKER_ID, H.NAME
FROM SUBMISSIONS S
INNER JOIN CHALLENGES C
ON S.CHALLENGE_ID = C.CHALLENGE_ID
INNER JOIN DIFFICULTY D
ON C.DIFFICULTY_LEVEL = D.DIFFICULTY_LEVEL
INNER JOIN HACKERS H
ON S.HACKER_ID = H.HACKER_ID
WHERE S.SCORE = D.SCORE
GROUP BY H.HACKER_ID, H.NAME
HAVING COUNT(H.HACKER_ID) > 1
ORDER BY COUNT(H.HACKER_ID) DESC, S.HACKER_ID ASC
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Top Competitors
You are viewing a single comment's thread. Return to all comments →
Your code throws an error, as h.name is not functionally dependent on the columns in the group by clause (h.name is not included in the group by clause) and to remove the redundancy just remove this condition, c.difficulty_level = d.difficulty_level. That should work. Here is my code, that worked fine for me,
SELECT H.HACKER_ID, H.NAME FROM SUBMISSIONS S INNER JOIN CHALLENGES C ON S.CHALLENGE_ID = C.CHALLENGE_ID INNER JOIN DIFFICULTY D ON C.DIFFICULTY_LEVEL = D.DIFFICULTY_LEVEL INNER JOIN HACKERS H ON S.HACKER_ID = H.HACKER_ID
WHERE S.SCORE = D.SCORE GROUP BY H.HACKER_ID, H.NAME HAVING COUNT(H.HACKER_ID) > 1 ORDER BY COUNT(H.HACKER_ID) DESC, S.HACKER_ID ASC