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

  1. Create a monthly aggregate first.
  2. Use a window function to access prior revenue.
  3. 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.