Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top 10 Products SQL Query

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top 10 Products SQL Query. Start with the requirements and the one table on the right.

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.

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results