Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Top Driver Earnings Per Hour
00:00
5 left

Top Driver Earnings Per Hour

MediumSQL · PostgreSQL

Problem

RideNow wants to identify its highest-efficiency drivers based on earnings per hour in the previous calendar month. Write a SQL query to return the drivers whose earnings per hour place them in the top 10% for that period.

Requirements

  1. Use only trips that were completed in the previous calendar month.
  2. For each driver, calculate:
    • total earnings as the sum of fare_amount
    • total hours worked as the sum of trip duration in hours
    • earnings per hour = total earnings / total hours worked
  3. Exclude drivers whose total worked hours are 0 or NULL.
  4. Return only drivers in the top 10% by earnings per hour using a ranking or percentile approach.
  5. Output driver_id, driver_name, total_earnings, total_hours, and earnings_per_hour, ordered by earnings_per_hour descending.

Schema

drivers
ColumnTypeDescription
driver_idPKINTUnique identifier for each driver
driver_nameVARCHAR(100)Driver full name
cityVARCHAR(50)Driver's primary city
active_statusVARCHAR(20)Current status of the driver
trips
ColumnTypeDescription
trip_idPKINTUnique identifier for each trip
driver_idINTDriver assigned to the trip
trip_statusVARCHAR(20)Trip completion status
started_atTIMESTAMPTrip start timestamp
ended_atTIMESTAMPTrip end timestamp
fare_amountDECIMAL(10,2)Fare earned from the trip
Tablesdriverstrips
Interviewer

Your question is Top Driver Earnings Per Hour. Start with the requirements and the two 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.