You are given two tables: Users and Register.
The Users table contains information about users with their user_id (primary key) and user_name.
The Register table contains contest registration data with contest_id and user_id as a composite primary key.
Task: Calculate the percentage of users who registered for each contest, rounded to 2 decimal places.
Output requirements:
- Order results by percentage in descending order
- For ties, order by
contest_idin ascending order - Return
contest_idandpercentagecolumns
Table Schema
| Column Name | Type | Description |
|---|---|---|
user_id
PK
|
int | Unique identifier for each user |
user_name
|
varchar | Name of the user |
| Column Name | Type | Description |
|---|---|---|
contest_id
PK
|
int | Identifier for the contest |
user_id
PK
|
int | User who registered for the contest |
Input & Output
| user_id | user_name |
|---|---|
| 1 | Alice |
| 2 | Bob |
| 3 | Charlie |
| 4 | David |
| contest_id | user_id |
|---|---|
| 208 | 1 |
| 208 | 2 |
| 210 | 2 |
| contest_id | percentage |
|---|---|
| 208 | 50 |
| 210 | 25 |
Contest 208 has 2 registrations out of 4 total users: (2/4) × 100 = 50.00%. Contest 210 has 1 registration out of 4 total users: (1/4) × 100 = 25.00%. Results are ordered by percentage descending.
| user_id | user_name |
|---|---|
| 1 | Alice |
| 2 | Bob |
| contest_id | user_id |
|---|---|
| 215 | 1 |
| 220 | 2 |
| contest_id | percentage |
|---|---|
| 215 | 50 |
| 220 | 50 |
Both contests have the same percentage (50.00%), so they are ordered by contest_id in ascending order: 215 comes before 220.
Constraints
-
1 ≤ user_id ≤ 1000 -
1 ≤ contest_id ≤ 1000 - Each user can register for multiple contests
- Each (contest_id, user_id) pair is unique in Register table