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 Products Per Region Query
00:00
5 left

Top Products Per Region Query

MediumSQL · PostgreSQL

Problem

Apex Systems wants a quarterly view of product performance in its sales analytics reporting. Write a PostgreSQL query that identifies the highest-grossing products in each sales region for the last completed quarter, defined here as April 1, 2025 through June 30, 2025.

Requirements

  1. Join regions, orders, order_items, and products to calculate product revenue by region.
  2. Include only orders whose order_date falls within the specified quarter.
  3. Calculate gross revenue as quantity * unit_price and aggregate it by region and product.
  4. Use a window function to return all products whose rank is within the top three positions per region. Products tied at a qualifying rank must all be included.
  5. Return region_name, product_name, gross_revenue, and the ranking value, ordered by region and revenue descending.

Schema

regions
ColumnTypeDescription
region_idPKINTUnique sales region identifier
region_nameVARCHAR(50)Sales region name
region_managerVARCHAR(100)Assigned region manager
products
ColumnTypeDescription
product_idPKINTUnique product identifier
product_nameVARCHAR(100)Product name
categoryVARCHAR(50)Product category
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
region_idINTRegion associated with the order
order_dateDATEOrder placement date
order_items
ColumnTypeDescription
order_item_idPKINTUnique order line identifier
order_idINTParent order identifier
product_idINTSold product identifier
quantityINTUnits sold
unit_priceNUMERIC(10,2)Selling price per unit
Tablesregionsproductsordersorder_items
Interviewer

Your question is Top Products Per Region Query. Start with the requirements and the four 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.