Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Top 10 Products by Sales

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

Your question is SQL Top 10 Products by Sales. 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

Business context

SMX tracks product-level sales events in its commerce reporting pipeline. The data science team needs a quick ranking of products with the highest completed sales volume.

Task

Write a PostgreSQL query to return the top 10 SMX products by total completed units sold.

Requirements

  1. Include only rows where sale_status is completed, then group records by product_name and sum units_sold.
  2. Return product_name and total_units_sold, ordered from highest to lowest volume. Treat a product with only missing unit values as zero, and use product name as a deterministic tie-breaker.

Schema

smx_product_sales
ColumnTypeDescription
sale_idPKINTUnique identifier for a product sales event.
product_nameVARCHAR(100)Name of the SMX product.
units_soldINTNumber of units in the sales event.
sale_statusVARCHAR(20)Processing status of the sales event.
sale_dateDATEDate the sales event was recorded.
Tablessmx_product_sales
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results