Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Year-over-Year Product Growth

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

Your question is Year-over-Year Product Growth. 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

Stryker's commercial analytics team wants to monitor annual sales performance for the Mako product line. Write a PostgreSQL query that calculates year-over-year sales growth from the available sales records.

Requirements

  1. Join sales to products and include only products where product_line = 'Mako'.
  2. Aggregate total sales by calendar year using sale_date and sales_amount.
  3. Compare each year with the immediately preceding year and calculate growth as a percentage.
  4. Return the years in ascending order. Return NULL for the first year when no prior-year sales exist.

Schema

products
ColumnTypeDescription
product_idPKINTEGERUnique product identifier
product_nameVARCHAR(100)Name of the Stryker product
product_lineVARCHAR(50)Stryker product line associated with the product
sales
ColumnTypeDescription
sale_idPKINTEGERUnique sale identifier
product_idINTEGERProduct associated with the sale
sale_dateDATEDate on which the sale was recorded
sales_amountNUMERIC(12,2)Sales value for the transaction
Tablesproductssales
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results