Year-on-Year Growth Rate Calculation
 

Using the table playground.dates, write a SQL query to calculate the year-on-year growth rate for the total spend of each product. The output should include the year, product ID, current years spend, previous years spend, and the year-on-year growth percentage, rounded to 2 decimal places, grouped by product ID and sorted by year in ascending order.

These are the tables to query for this question:
playground.dates
  • transaction_id int
  • product_id int
  • spend double
  • transaction_date date
Your answer should include these columns:
  • year integer
  • product_id integer
  • current_year_spend double
  • previous_year_spend double
  • yoy_rate double

Querying is only for logged in users!

Write Your Query Here (you can run selections by highlighting!)

Query Results

No queries have been run yet.