Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL: Rides and Weekly Drivers

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL: Rides and Weekly Drivers. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Assume that we have the following tables, with columns as indicated: Rides ride_id start_time end_time passenger_id driver_id ride_region is_completed (Y/N) Drivers driver_id onboarding_time home_region

  1. Write a query that we could use to create a plot of the total count of rides completed in our San Francisco region, in each week over the last 12 weeks.

  2. For each week over the last 12 weeks, write a query that will return a count of the total drivers who gave at least one ride. And only for driver’s based in San Francisco.

Use start_time to assign rides to weeks and include weeks with zero activity.

Output

  1. Return week_start, metric_name, and metric_value, with one row per metric per week.
  2. Include the 12 most recent calendar weeks, ordered by week_start and then metric_name.

Schema

rides
ColumnTypeDescription
ride_idPKINTUnique ride identifier
start_timeTIMESTAMPRide start timestamp
end_timeTIMESTAMPRide end timestamp
passenger_idINTPassenger identifier
driver_idINTDriver identifier referencing drivers.driver_id
ride_regionVARCHAR(100)Region where the ride occurred
is_completedVARCHAR(1)Whether the ride completed, Y or N
drivers
ColumnTypeDescription
driver_idPKINTUnique driver identifier
onboarding_timeTIMESTAMPTimestamp when the driver completed onboarding
home_regionVARCHAR(100)Driver's home region
Tablesridesdrivers
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results