SQL
All Top 50 SQL Interview Questions#45
Calculate Month-over-Month Growth with LAG() in SQL
MediumFlipkartInterview Question #45
Asked at FlipkartGiven monthly revenue records, compute the month-over-month revenue percentage change: `((current - previous) / previous) * 100`, rounded to 2 decimal places.
Input Table: monthly_revenue
3 rows preview| revenue_month | revenue |
|---|---|
| 2026-01 | 100000 |
| 2026-02 | 125000 |
| 2026-03 | 118750 |
Expected Output Structure3 rows
| revenue_month | revenue | prev_revenue | mom_growth_pct |
|---|---|---|---|
| 2026-01 | 100000 | NULL | NULL |
| 2026-02 | 125000 | 100000 | 25 |
| 2026-03 | 118750 | 125000 | -5 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.