Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Calculate Monthly Sales Growth by Product Category

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Calculate Monthly Sales Growth by Product Category. Read through the requirements and the two tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

A retail company needs to analyze its sales performance. Write a SQL query to calculate the month-over-month sales growth for each product category.

Requirements

  1. Join the sales and products tables by product_id.
  2. Calculate total sales per category for each month.
  3. Determine the month-over-month growth percentage for each category.
  4. Order the results by category and month.

Schema

sales
ColumnTypeDescription
idPKINTPrimary key
product_idINTForeign key referencing products
sale_dateDATEDate of the sale
amountDECIMALSale amount
products
ColumnTypeDescription
idPKINTPrimary key
categoryVARCHAR(255)Product category
Tablessalesproducts
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results