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

Top-Performing Products Query

MediumSQL · PostgreSQL

Problem

Business context

Tesco's commercial team wants to identify the best-performing products in a specific quarter using product sales data.

Task

Write a PostgreSQL query that returns the top three Tesco products by revenue for Q2 2025, from 1 April through 30 June 2025.

Requirements

  1. Join the product catalogue to sales records and restrict sales to Q2 2025 using an inclusive start date and exclusive end date.
  2. Calculate total units sold and revenue for each product, using quantity * unit_price for revenue.
  3. Rank products by revenue in descending order and return the top three products, including ties if they occur.
  4. Exclude products with no positive Q2 revenue and sort the final output by rank.

Schema

products
ColumnTypeDescription
product_idPKINTEGERUnique product identifier
product_nameVARCHAR(150)Tesco product name
categoryVARCHAR(80)Product category
sales
ColumnTypeDescription
sale_idPKINTEGERUnique sale identifier
product_idINTEGERProduct sold, referencing products.product_id
sale_dateDATEDate on which the sale occurred
quantityINTEGERNumber of units sold
unit_priceNUMERIC(10,2)Selling price per unit
Tablesproductssales
Interviewer

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