WITH yearly_sales AS (SELECT strftime('%Y', order_date) AS year, SUM(amount) AS total FROM orders GROUP BY year) SELECT year, total, LAG(total) OVER (ORDER BY year) AS prev_year_total, (total - LAG(total) OVER (ORDER BY year)) * 100.0 / LAG(total) OVER (ORDER BY year) AS yoy_growth FROM yearly_sales;
Write your query and click "Run Query" (Ctrl + Enter) to see results and testcase validation.