How would you compute month-over-month growth?

SQL aggregates and GROUP BY · Experienced

Model answer

Aggregate by month, then use LAG: SELECT month, total, (total - LAG(total) OVER (ORDER BY month)) * 100.0 / LAG(total) OVER (ORDER BY month) AS growth FROM monthly. Handle the first month (NULL) and division by zero.

Learn this topic

GROUP BY and HAVING: Summaries for Each Group in the course SQL for Beginners: Learn Databases Step by Step.

Sign in to add your own answer.

More questions