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

Top 10 Products SQL Query

EasySQL · PostgreSQL

Problem

Artefact's commerce analytics team needs a monthly view of its strongest-selling products. Write a PostgreSQL query using the product_sales table to find the top 10 products by total sales during the previous calendar month. For the sample data, assume the current date is 2026-08-29, so the reporting period is July 2026.

Requirements

  1. Include only sales from the previous calendar month, excluding the current month and earlier months.
  2. Group rows by product_name, calculate total sales, sort from highest to lowest, and return at most 10 products.

Schema

product_sales
ColumnTypeDescription
sale_idPKINTUnique identifier for the sale
product_nameVARCHAR(100)Name of the product sold
sale_dateDATECalendar date on which the sale occurred
sale_amountNUMERIC(12,2)Revenue attributed to the sale
Tablesproduct_sales
Interviewer

Your question is Top 10 Products SQL Query. Start with the requirements and the one table 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.