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 KPI Trends With YoY
00:00
5 left

SQL KPI Trends With YoY

MediumSQL · PostgreSQL

Problem

Write a SQL query to calculate monthly KPI trends with year-over-year comparison for Volvo Group.

Use completed deliveries for valid Volvo Group vehicle models sold through active dealer locations. Include months with no prior-year comparison, and calculate delivery volume, revenue, revenue per vehicle, and year-over-year percentage changes.

Output

  1. One row per calendar month with columns month_start, delivered_units, total_revenue, revenue_per_vehicle, prior_year_units, prior_year_revenue, units_yoy_pct, and revenue_yoy_pct.
  2. Include all qualifying months, sort chronologically, and return NULL percentage values when no prior-year baseline exists or the baseline is zero.

Schema

vehicle_deliveries
ColumnTypeDescription
delivery_idPKINTUnique delivery identifier
model_idINTVehicle model reference
dealer_idINTDealer location reference
delivery_dateDATEDate of delivery
statusVARCHAR(20)Delivery status
net_revenueNUMERIC(14,2)Net revenue recognized for the delivery
vehicle_models
ColumnTypeDescription
model_idPKINTUnique vehicle model identifier
model_nameVARCHAR(80)Vehicle model name
vehicle_typeVARCHAR(40)Vehicle category
brandVARCHAR(60)Vehicle brand
dealer_locations
ColumnTypeDescription
dealer_idPKINTUnique dealer identifier
dealer_nameVARCHAR(100)Dealer name
countryVARCHAR(50)Dealer country
regionVARCHAR(50)Commercial region
activeBOOLEANWhether the dealer is currently active
Tablesvehicle_deliveriesvehicle_modelsdealer_locations
Interviewer

Your question is SQL KPI Trends With YoY. 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.