logo

Back to questions

2nd Ride Delay

Medium

As a data analyst at Uber, it's your job to report the latest metrics for specific groups of Uber users. Some riders create their Uber account on the same day that they book their first ride; the rider engagement team calls them "in-the-moment" users.

Uber wants to know the average delay between the day these users signed up and the day of their 2nd ride. Write a query to pull the average 2nd ride delay for "in-the-moment" Uber users.

Assumptions

  • Round the answer to 2 decimals
  • The delay should be measured in integer days (i.e. 1, 2, 3)

Tip You don't need to use date operations to get the answer! You're welcome to, but it's not necessary.

Table:

Column NameType
user_idinteger
registration_datedate

Example Input:

user_idregistration_date
108/15/2022
208/21/2022

Table:

Column NameType
ride_idinteger
user_idinteger
ride_datedate

Example Input:

ride_iduser_idride_date
1108/15/2022
2108/16/2022
3209/20/2022
4209/23/2022

Example Output:

average_delay
1

Explanation:

  1. We don't include user 2 in the calculation because the user was not created on the same date as the first ride.
  2. For the user 1, the difference between first and second ride was 1 day; thus, the overall average is 1 day.

PostgreSQL 14

Refer friends to get bonus content & cool prizes.