P17SQLIntermediateCalculate14 min
Monthly Revenue Growth
Calculate month-over-month revenue growth while handling a month with no prior comparison.
#window-functions#lag#time-series
Scenario
Finance needs a monthly revenue trend with a growth percentage for each month.
Problem statement
Aggregate revenue by month and compare each month to the prior month.
Your Task
- Create a monthly aggregate first.
- Use a window function to access prior revenue.
- Avoid dividing by zero or missing prior values.
Table
orders(order_date, amount, status)
Related Concepts
CTEsLAGGrowth metrics
Ready to count this problem?
Mark it complete when you have reasoned through the solution in your own words.