User Contest Attendance

2pts
Meta

Problem Statement

Engagement teams at Meta want to track which contests are most popular among the user base. You need to determine the registration percentage for every contest.

Write an SQL query to find the percentage of the users registered in each contest rounded to two decimals.

Rules:

  • The percentage is calculated as (Users Registered in Contest / Total Users in Users Table) * 100.
  • Round the result to exactly 2 decimal places.
  • Return the contest_id and the percentage.
  • Results must be sorted by percentage in descending order. In case of a tie, sort by contest_id in ascending order.
Tests your understanding of
Basic SQL, Aggregation, Subquery, Rounding and Math Functions

Input Tables

users
user_id(INTEGER)user_name(VARCHAR)
6Alice
2Bob
7Alex
register
contest_id(INTEGER)user_id(INTEGER)
2156
2092
2082
2106
2086
2097
2096
2157
2087
2102
2072
2107

Expected Output

contest_id(INTEGER)percentage(FLOAT)
208100
209100
210100
21566.67
20733.33

Tags

EasyBasic SQLAggregationSubqueryRoundingMath Functions
10-15 min
65%

Hints