Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Weekly Driver Earnings by City

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

Your question is Rank Weekly Driver Earnings by City. Start with the requirements and the three 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

You are given Lyft earnings data at the ride level. Write a PostgreSQL query that returns each driver's total earnings for each week and ranks drivers within their city for that week based on total weekly earnings. Use a window function so that drivers with the same weekly earnings receive the same rank.

Schema

drivers
ColumnTypeDescription
driver_idPKINTUnique driver identifier
driver_nameVARCHAR(100)Driver full name
city_idINTDriver's primary Lyft city
cities
ColumnTypeDescription
city_idPKINTUnique city identifier
city_nameVARCHAR(100)Lyft city name
ride_earnings
ColumnTypeDescription
ride_idPKINTUnique ride identifier
driver_idINTDriver who completed the ride
ride_dateDATERide completion date
earnings_amountDECIMAL(10,2)Driver earnings from the ride
Tablesdriverscitiesride_earnings
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results