Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Products by Monthly Volume

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

Your question is Top Products by Monthly Volume. Start with the requirements and the two tables 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

DHL Supply Chain needs a monthly view of which products generate the highest shipment volume. Write a PostgreSQL query that ranks products within each calendar month using completed shipment quantities.

Requirements

  1. Join shipment records to the product master and aggregate quantity by month and product.
  2. Include only shipments with status = 'Completed'.
  3. Return the top three products for each month, using ROW_NUMBER() and ordering ties alphabetically by product name.
  4. Return the month, product name, total shipment volume, and rank, ordered by month and rank.

Schema

shipments
ColumnTypeDescription
shipment_idPKINTUnique shipment identifier
product_idINTProduct associated with the shipment
shipment_dateDATEDate on which the shipment was recorded
quantityINTNumber of product units shipped
statusVARCHAR(20)Shipment processing status
products
ColumnTypeDescription
product_idPKINTUnique product identifier
product_nameVARCHAR(100)Product name
product_categoryVARCHAR(50)Product classification
Tablesshipmentsproducts
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results