You have two tables: Signups and Confirmations.
The Signups table contains information about when users signed up, with columns for user_id and time_stamp.
The Confirmations table tracks confirmation requests, with columns for user_id, time_stamp, and action (either 'confirmed' or 'timeout').
Your task: Calculate the confirmation rate for each user. The confirmation rate is the number of 'confirmed' messages divided by the total number of requested confirmation messages. If a user didn't request any confirmations, their rate is 0. Round the result to two decimal places.
Table Schema
| Column Name | Type | Description |
|---|---|---|
user_id
PK
|
int | Unique identifier for each user |
time_stamp
|
datetime | When the user signed up |
| Column Name | Type | Description |
|---|---|---|
user_id
PK
|
int | Foreign key referencing Signups.user_id |
time_stamp
PK
|
datetime | When the confirmation was requested |
action
|
ENUM | Result of confirmation: 'confirmed' or 'timeout' |
Input & Output
| user_id | time_stamp |
|---|---|
| 3 | 2020-03-21 10:16:13 |
| 7 | 2020-01-04 13:57:59 |
| 2 | 2020-07-29 23:09:44 |
| 6 | 2020-12-09 10:39:37 |
| user_id | time_stamp | action |
|---|---|---|
| 3 | 2021-01-06 03:30:46 | timeout |
| 3 | 2021-07-14 14:00:00 | timeout |
| 7 | 2021-06-12 11:57:29 | confirmed |
| 7 | 2021-06-13 12:58:28 | confirmed |
| 7 | 2021-06-14 13:59:27 | confirmed |
| 2 | 2021-01-22 00:00:00 | confirmed |
| 2 | 2021-02-28 23:59:59 | timeout |
| user_id | confirmation_rate |
|---|---|
| 6 | 0 |
| 3 | 0 |
| 7 | 1 |
| 2 | 0.5 |
User 6 made no confirmation requests, so rate is 0.00. User 3 had 2 timeouts (0/2 = 0.00). User 7 confirmed all 3 requests (3/3 = 1.00). User 2 confirmed 1 out of 2 requests (1/2 = 0.50).
| user_id | time_stamp |
|---|---|
| 1 | 2020-01-01 00:00:00 |
| 2 | 2020-01-02 00:00:00 |
| user_id | time_stamp | action |
|---|
| user_id | confirmation_rate |
|---|---|
| 1 | 0 |
| 2 | 0 |
Both users signed up but never requested any confirmations. Their confirmation rates are 0.00 as specified in the problem requirements.
Constraints
-
1 ≤ user_id ≤ 1000 -
actionis either'confirmed'or'timeout' -
time_stampis a valid datetime