Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Categories by Shipping Growth

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

Your question is Top Categories by Shipping Growth. 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

ShopSwift wants to identify which product categories are driving shipping cost increases. Write a SQL query to find the top categories contributing to shipping cost growth from February 2024 to March 2024.

Requirements

  1. Use only the shipments table.
  2. For each category, calculate total shipping cost in February 2024 and March 2024.
  3. Return only categories where March shipping cost is greater than February shipping cost.
  4. Output the category, February total, March total, and the growth amount (march_total - february_total).
  5. Sort by growth amount in descending order and return the top 3 categories.

Schema

shipments
ColumnTypeDescription
shipment_idPKINTUnique shipment record ID
categoryVARCHAR(50)Product category for the shipped item
shipped_dateDATEDate the shipment was sent
shipping_costDECIMAL(10,2)Shipping cost for the shipment
carrierVARCHAR(50)Carrier used for the shipment
Tablesshipments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results