Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Products SQL Query
00:00
5 left

Top Products SQL Query

EasySQL · PostgreSQL

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
Interviewer

Your question is Top 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.