Y-on-Y Growth Rate

ASKED IN INTERVIEW
10pts
Wayfair

Problem Statement

Calculate the year-over-year revenue growth for each product.

Rules:

  • Output columns: product_id, year, current_year_revenue, previous_year_revenue, yoy_growth_percentage.
  • Revenue = sum of (unit_price * quantity).
  • Growth = ((Current - Previous) / Previous) * 100.
  • Round percentages to 2 decimal places.
  • Sort by product_id ASC and year ASC.
Tests your understanding of
LAG, Window Functions, Aggregation and Date Extraction

Input Tables

products
product_id(INTEGER)product_name(VARCHAR)unit_price(DECIMAL)
1Velvet Sofa500
2Oak Desk200
orders
order_id(INTEGER)product_id(INTEGER)quantity(INTEGER)order_date(DATE)
101122023-05-10
102132024-06-15
103252023-01-01
1042102024-01-01
product_categories
product_id(INTEGER)category_name(VARCHAR)
1Living Room
2Office

Expected Output

product_id(INTEGER)year(INTEGER)current_year_revenue(DECIMAL)previous_year_revenue(DECIMAL)yoy_growth_percentage(DECIMAL)
120231000nullnull
120241500100050
220231000nullnull
2202420001000100

Tags

HardASKED IN INTERVIEWLAGWindow FunctionsAggregationDate Extraction
25-30 min
32%

Hints