SQL interview question: Year-over-Year Revenue Growth

Year-Over-Year Revenue Growth Analysis

Finance needs a report showing how each product category's revenue has grown compared to the previous year.

Calculate year-over-year revenue growth percentage for each category using LAG() window function.

Return category, year, total_revenue, and growth_pct. Only show years where previous year data exists.

Inspired by e-commerce analytics challenges

Tables

category_revenue 6 rows
  • id integer PK
  • category text
  • year integer
  • total_revenue real
idcategoryyeartotal_revenue
1Electronics2023500000.0
2Electronics2024600000.0
3Furniture2023300000.0

Keep going