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
SQL for City Performance
00:00
5 left

SQL for City Performance

HardSQL · PostgreSQL

Problem

Write a SQL query to analyze operational performance by city, joining trip data, maintenance records, and city-level targets to identify underperforming markets for Spin.

Use the target month in city_targets as the reporting period. Include cities with no trips or maintenance records, and treat only completed trips as operational trips.

Output

  1. One row per underperforming city and target month
  2. Columns: city_name, target_month, completed_trips, total_revenue, maintenance_events, maintenance_rate_pct, target_completed_trips, target_revenue, max_maintenance_rate_pct, previous_completed_trips, completed_trip_change, and failure_count
  3. Include cities below either trip or revenue targets, or above the maximum maintenance rate
  4. Order by failure_count descending, then city_name ascending

Schema

trips
ColumnTypeDescription
trip_idPKINTUnique trip identifier
scooter_idINTScooter used for the trip
city_idINTSpin city identifier
trip_dateDATEDate the trip occurred
statusVARCHAR(20)Trip status
duration_minutesINTTrip duration in minutes
revenueNUMERIC(10,2)Revenue generated by the trip
maintenance_records
ColumnTypeDescription
maintenance_idPKINTUnique maintenance record identifier
scooter_idINTScooter receiving maintenance
city_idINTCity where maintenance occurred
maintenance_dateDATEDate maintenance was recorded
issue_typeVARCHAR(30)Maintenance issue category
downtime_hoursNUMERIC(6,2)Estimated scooter downtime
resolved_dateDATEDate the issue was resolved
city_targets
ColumnTypeDescription
target_idPKINTUnique target record identifier
city_idINTSpin city identifier
city_nameVARCHAR(50)Spin city name
target_monthDATEFirst day of the target month
target_completed_tripsINTExpected completed trips
target_revenueNUMERIC(10,2)Expected trip revenue
max_maintenance_rate_pctNUMERIC(6,2)Maximum acceptable maintenance events as a percentage of completed trips
Tablestripsmaintenance_recordscity_targets
Interviewer

Your question is SQL for City Performance. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.