SQL
All Top 50 SQL Interview Questions#27
Calculate Contest Participation Percentage in SQL
EasyInterview Question #27
Given `users` (user_id) and `register` (contest_id, user_id), find the percentage of total users registered in each contest, rounded to 2 decimal places. Sort by percentage descending, then contest_id ascending.
Input Table: users & register
3 rows preview| user_id | contest_id |
|---|---|
| 6 | 215 |
| 6 | 209 |
| 7 | 215 |
Expected Output Structure2 rows
| contest_id | percentage |
|---|---|
| 215 | 66.67 |
| 209 | 33.33 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.