408. Year-Over-Year (YoY) Growth

Medium Finance Growth Metrics
Query Rules
  • The query columns and order must match the expected result schema.
  • NULL values should be handled appropriately where applicable.
  • The grader compares output values and sorting order to evaluate.

Schema Browser

Click a table's header to toggle expand/collapse.
locations
3 cols
departments
3 cols
employees
6 cols
orders
6 cols

Reference Solution

Expected SQL
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;
SQL Editor
Ctrl+Enter to run
Console Output

Console Terminal

Write your query and click "Run Query" (Ctrl + Enter) to see results and testcase validation.