Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Products SQL Query

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

Your question is Top 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

Saint-Gobain's commercial analytics team wants to identify the products with the highest sales volume. Using the product_sales table, write a PostgreSQL query that ranks products by the total number of units sold.

Requirements

  1. Group sales records by product_name and calculate total units sold with SUM.
  2. Return the five products with the highest totals, ordered from highest to lowest. Use product name ascending as a tie-breaker.

Schema

product_sales
ColumnTypeDescription
sale_idPKINTUnique sales record identifier
product_nameVARCHAR(100)Saint-Gobain product name
quantityINTUnits sold in the sales record
sale_dateDATEDate of the sale
Tablesproduct_sales
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results