Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
City Ride Demand SQL Analysis
00:00
5 left

City Ride Demand SQL Analysis

MediumSQL · PostgreSQL

Problem

Write a SQL query to analyze city-level ride demand, driver supply, and conversion trends over time for Didi Chuxing.

Use the cities, ride_requests, and driver_sessions tables. Report monthly metrics for the available reporting period, excluding requests without a valid city.

Output

  1. One row per city and month with ride requests, completed rides, active drivers, and conversion rate.
  2. Columns: city_name, month, ride_requests, completed_rides, active_drivers, conversion_rate.
  3. Sort by city_name, then month ascending.

Schema

cities
ColumnTypeDescription
city_idPKINTUnique city identifier
city_nameVARCHAR(100)Didi service city name
ride_requests
ColumnTypeDescription
request_idPKINTUnique ride request identifier
city_idINTRequested pickup city
requested_atTIMESTAMPTimestamp when the ride was requested
statusVARCHAR(20)Ride outcome, such as completed or cancelled
driver_sessions
ColumnTypeDescription
session_idPKINTUnique driver session identifier
city_idINTCity where the driver was available
driver_idINTDriver identifier
session_dateDATEDate of the driver session
online_minutesINTMinutes the driver was online
Tablescitiesride_requestsdriver_sessions
Interviewer

Your question is City Ride Demand SQL Analysis. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.