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
| id | category | year | total_revenue |
|---|---|---|---|
| 1 | Electronics | 2023 | 500000.0 |
| 2 | Electronics | 2024 | 600000.0 |
| 3 | Furniture | 2023 | 300000.0 |