Good job! Now that we know how to calculate the revenue value for the previous period, we can easily calculate the revenue change (delta) between two periods. Take a look:
EXTRACT(year FROM order_date) AS revenue_year,
SUM(amount) AS total_revenue,
SUM(amount) - LAG(SUM(amount), 1) OVER (ORDER BY EXTRACT(year FROM order_date)) AS delta
GROUP BY EXTRACT(year FROM order_date)
ORDER BY EXTRACT(year FROM order_date);
delta column, we simply subtracted the revenue generated in the previous year from the revenue generated in the current year. Once again, we used the
LAG() function pattern from the previous exercise.