Percentage of Users Attended a Contest
Preview mode. Log in to edit, run, submit, and save progress.
Medium
Percentage of Users Attended a Contest
You have two tables: Users and Register. The Register table records which users signed up for which contests. Write a SQL query to find the percentage of users registered in each contest, rounded to 2 decimal places. Return the result ordered by percentage descending. If there is a tie, order by contest_id ascending. (contest_id, user_id) is the primary key.
Examples
Example 1
Contests 208, 209, 210 had all 3 users (100%). Contest 215 had 2/3 users (66.67%). Contest 207 had 1/3 users (33.33%).
Approach hint
Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.
query.sql