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-Performing Segments Query
00:00
5 left

Top-Performing Segments Query

MediumSQL · PostgreSQL

Problem

Volkswagen Group Italia needs a quarterly view of its strongest product segments across the latest three quarters of available sales data. Write a PostgreSQL query that ranks segments by net revenue and returns the top two segments for each quarter.

Requirements

  1. Determine the latest quarter from the available sale_date values and include that quarter plus the two preceding quarters.
  2. Join sales to products and product segments, then aggregate net revenue and units by quarter and segment.
  3. Rank segments within each quarter by total revenue in descending order and return only ranks 1 and 2.
  4. Return results ordered chronologically by quarter and then by revenue rank.

Schema

product_segments
ColumnTypeDescription
segment_idPKINTUnique product segment identifier
segment_nameVARCHAR(80)Commercial product segment name
products
ColumnTypeDescription
product_idPKINTUnique product identifier
product_nameVARCHAR(120)Vehicle or product name
segment_idINTReferenced product segment
sales
ColumnTypeDescription
sale_idPKINTUnique sale identifier
product_idINTReferenced product
sale_dateDATEDate on which the sale was recorded
unitsINTNumber of units sold
net_revenueNUMERIC(12,2)Net sales revenue in euros
Tablessalesproductsproduct_segments
Interviewer

Your question is Top-Performing Segments Query. 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.