Excluding Records Based on a Condition

Link: https://www.hackerrank.com/challenges/challenges/problem

The question is asking is to use an aggregate function to sum the total amount of challenges created by each user. If the sum of the number of challenges created is equal to the maximum count, then we can allow users who created the same number of challenges. If multiple users had the same number of challenges created less than the max count, then we must exclude those from the table. We need to break this problem into two parts.

First, we need to extract the users who created a total number of challenges less than the maximum. These users must have also obtained a unique total count.

Next, we need to extract the records that have a count of challenges equal to the maximum count in the table.

Finally, we can combine both with the UNION operator and wrap the entire query as a subquery, as we still need to sort by the number of challenges created. After that, we can extract what we need from the subquery. Here is the final query in its entirety.

About the author

programmingforfinance

Hi, I'm Frank. I have a passion for coding and extend it primarily within the realm of Finance.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *