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 Top Products by Region
00:00
5 left

SQL Top Products by Region

MediumSQL · PostgreSQL

Problem

Roche's commercial analytics team needs a regional view of product performance. Assume the reporting date is 2025-07-15, so the last completed quarter is 2025-04-01 through 2025-06-30.

Write a PostgreSQL query to identify the top three Roche products by revenue in each region.

Requirements

  1. Join sales, products, and regions using their key relationships.
  2. Include only sales from the last completed quarter, using an inclusive start date and exclusive end date.
  3. Calculate revenue as quantity * unit_price and aggregate it by region and product.
  4. Rank products within each region by descending revenue with RANK(), retaining ties at the third rank.
  5. Return region, product, total revenue, and rank, ordered by region, rank, and product name.

Schema

sales
ColumnTypeDescription
sale_idPKINTUnique sales record identifier
product_idINTReferences products.product_id
region_idINTReferences regions.region_id
sale_dateDATEDate on which the sale was recorded
quantityINTNumber of units sold
unit_priceDECIMAL(12,2)Revenue per unit in reporting currency
products
ColumnTypeDescription
product_idPKINTUnique Roche product identifier
product_nameVARCHAR(100)Roche product name
regions
ColumnTypeDescription
region_idPKINTUnique commercial region identifier
region_nameVARCHAR(100)Commercial region name
Tablessalesproductsregions
Interviewer

Your question is SQL Top Products by Region. 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.