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.
In a literal sense, aliasing (like the use of "counts") helps you follow that the immediately prior code represents a logical "table" of values, and in many cases is required by MySQL.
In the step above the portion involving "counts" (the first instance of a HAVING clause), we find the max number of challlenges for all hackers. In the following step (c_count IN...) we look to see (if they haven't completed the max number of challenges... hence "OR") if the count of challenges they have completed is unique (not shared by other hackers).
The alias "counts" represents our compared to "table" of challenge values (done by grouping it by counts of challenges). We then check to see if c_count (COUNT(c.challege_id) from Hackers) is a unique number of challenges completed. In other words, the count(challeng_id) aliased as "c_compare" is unique when the count of the HAVING clause equals 1. It (the particular value of challenges completed) is unique because when compared, there is only one instance of that count of challenges completed.
This is all done to meet this requirement in the problem: "If more than one student created the same number of challenges AND the count is less than the maximum number of challenges created, then exclude those students from the result."
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Challenges
You are viewing a single comment's thread. Return to all comments →
In a literal sense, aliasing (like the use of "counts") helps you follow that the immediately prior code represents a logical "table" of values, and in many cases is required by MySQL.
In the step above the portion involving "counts" (the first instance of a HAVING clause), we find the max number of challlenges for all hackers. In the following step (c_count IN...) we look to see (if they haven't completed the max number of challenges... hence "OR") if the count of challenges they have completed is unique (not shared by other hackers).
The alias "counts" represents our compared to "table" of challenge values (done by grouping it by counts of challenges). We then check to see if c_count (COUNT(c.challege_id) from Hackers) is a unique number of challenges completed. In other words, the count(challeng_id) aliased as "c_compare" is unique when the count of the HAVING clause equals 1. It (the particular value of challenges completed) is unique because when compared, there is only one instance of that count of challenges completed.
This is all done to meet this requirement in the problem: "If more than one student created the same number of challenges AND the count is less than the maximum number of challenges created, then exclude those students from the result."