Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Riders by City
00:00
5 left

Top Riders by City

MediumSQL · PostgreSQL

Problem

Lyft city operations wants to identify the highest-spending riders in each market. Write a PostgreSQL query using Lyft ride data to return the top five riders by completed-trip spending during the past quarter, represented here as 2025-04-01 through 2025-06-30.

Requirements

  1. Include only completed rides requested during the quarter.
  2. Calculate total spending for each rider within their city, treating NULL fares as zero.
  3. Rank riders independently within each city and return no more than five riders per city.
  4. Order results by city and spending rank.

Schema

cities
ColumnTypeDescription
city_idPKINTUnique city identifier
city_nameVARCHAR(100)Lyft market name
riders
ColumnTypeDescription
rider_idPKINTUnique rider identifier
rider_nameVARCHAR(100)Rider's display name
city_idINTRider's associated city
rides
ColumnTypeDescription
ride_idPKINTUnique ride identifier
rider_idINTRider who requested the ride
fare_amountDECIMAL(10,2)Fare charged for the ride
requested_atTIMESTAMPRide request timestamp
statusVARCHAR(20)Ride lifecycle status
Tablescitiesridersrides
Interviewer

Your question is Top Riders by City. 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.