Chapter 7 · CTEs
09. Month-over-Month Revenue Growth Rate
Hard40 XPE-Commerce
Calculate the month-over-month revenue growth rate. Use a CTE for monthly revenue, then use LAG to get the previous month's revenue. Compute growth as (current - previous) / previous * 100, rounded to 2 decimals. Sort by month.
Tables
- PKidINT
- FKcustomer_id→ customers.idINT
- order_dateTEXT
- statusTEXT
- total_amountREAL
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.