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
Rank Vehicles Within Regions
00:00
5 left

Rank Vehicles Within Regions

EasySQL · PostgreSQL

Problem

Lucid Motors wants to compare vehicle charging activity across geographic regions. Write a PostgreSQL query that ranks registered Lucid vehicles by total charging energy during Q1 2025.

Requirements

  1. Include every vehicle registered in the vehicles table, including vehicles with no qualifying charging sessions.
  2. Calculate each vehicle's total energy_kwh from charging sessions between January 1 and March 31, 2025. Treat missing or entirely NULL energy values as zero.
  3. Rank vehicles within their region using RANK(), with the highest total energy receiving rank 1. Preserve ties with the same rank.
  4. Return region, vehicle_id, model, total_energy_kwh, and regional_rank, ordered by region, rank, and vehicle ID.

Schema

vehicles
ColumnTypeDescription
vehicle_idPKINTUnique vehicle identifier
modelVARCHAR(50)Lucid vehicle model and trim
regionVARCHAR(50)Sales or service region
charging_sessions
ColumnTypeDescription
session_idPKINTUnique charging session identifier
vehicle_idINTVehicle associated with the session
session_dateDATEDate of the charging session
energy_kwhNUMERIC(8,2)Energy delivered during the session
Tablesvehiclescharging_sessions
Interviewer

Your question is Rank Vehicles Within Regions. 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.