Confirmation Rate

4pts
Tik Tok

Problem Statement

To evaluate the effectiveness of the multi-factor authentication system, the security team needs to track how often users successfully confirm their sign-up requests.

The confirmation rate of a user is the number of confirmed messages divided by the total number of requested confirmation messages. Users who did not request any confirmation messages have a confirmation rate of 0.

Write an SQL query to find the confirmation rate of each user.

Rules:

  • The confirmation rate must be rounded to 2 decimal places.
  • Every user from the Signups table must be included in the final report.
  • Return the result table containing user_id and confirmation_rate.
  • Results must be sorted by confirmation_rate in ascending order.
Tests your understanding of
Basic SQL, LEFT JOIN, CASE WHEN, Rounding and Aggregation

Input Tables

signups
user_id(INTEGER)time_stamp(TIMESTAMP)
32024-03-21 10:10:23
72024-03-20 12:35:00
22024-03-22 09:00:14
62024-03-22 15:45:00
confirmations
user_id(INTEGER)time_stamp(TIMESTAMP)action(ENUM('confirmed', 'timeout'))
32024-03-21 10:12:00confirmed
72024-03-20 12:35:10confirmed
72024-03-20 12:35:50timeout
22024-03-22 09:01:00confirmed
22024-03-22 09:02:00timeout

Expected Output

user_id(INTEGER)confirmation_rate(FLOAT)
60
20.5
70.5
31

Tags

MediumBasic SQLLEFT JOINCASE WHENRoundingAggregation
15-20 min
54%

Hints