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 Service Stations by Revenue
00:00
5 left

Top Service Stations by Revenue

HardSQL · PostgreSQL

Problem

Write a query to find the top three performing service stations in each region based on monthly revenue at Repsol. Use completed sales only and report each station's revenue by calendar month. Return no more than three stations per region and month, resolving equal revenues by the lower station ID.

Output

  1. One row per included station, region, and calendar month.
  2. Columns: region_name, revenue_month, station_id, station_name, monthly_revenue, and station_rank.
  3. Order by revenue_month, region_name, and station_rank ascending.

Schema

regions
ColumnTypeDescription
region_codePKVARCHAR(10)Unique code identifying a Repsol operating region
region_nameVARCHAR(100)Name of the operating region
service_stations
ColumnTypeDescription
station_idPKINTUnique service station identifier
station_nameVARCHAR(150)Service station name
region_codeVARCHAR(10)Operating region for the station
fuel_sales
ColumnTypeDescription
sale_idPKINTUnique sales transaction identifier
station_idINTStation where the sale occurred
sale_dateDATEDate of the sales transaction
revenueNUMERIC(12,2)Revenue generated by the transaction
statusVARCHAR(20)Transaction status
Tablesregionsservice_stationsfuel_sales
Interviewer

Your question is Top Service Stations by Revenue. 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.