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 Top Service Categories
00:00
5 left

Rank Top Service Categories

EasySQL · PostgreSQL

Problem

ServiceTitan wants to compare service-category performance across operating regions. Write a PostgreSQL query that identifies the top three service categories in each region based on completed job revenue during January 2025.

Requirements

  1. Join the regional, service-category, and job data.
  2. Include only jobs with status = 'completed' and completion dates in January 2025.
  3. Aggregate completed invoice revenue by region and service category.
  4. Use RANK() or DENSE_RANK() to return every category whose rank is 3 or better, including ties. Sort the final output by region, revenue descending, and category name.

Schema

regions
ColumnTypeDescription
region_idPKINTEGERUnique operating region identifier
region_nameVARCHAR(100)Operating region name
service_categories
ColumnTypeDescription
category_idPKINTEGERUnique service category identifier
category_nameVARCHAR(100)ServiceTitan service category name
jobs
ColumnTypeDescription
job_idPKINTEGERUnique job identifier
region_idINTEGERReferences regions.region_id
category_idINTEGERReferences service_categories.category_id
statusVARCHAR(30)Job lifecycle status
completed_atDATEDate the job was completed
invoice_totalNUMERIC(12,2)Total invoiced amount for the job
Tablesregionsservice_categoriesjobs
Interviewer

Your question is Rank Top Service Categories. 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.