Year-over-Year Revenue Growth
Beginner Mode

Objective

Write an SQL query that calculates the yearly revenue, the previous year's revenue, and the percentage growth in revenue year-over-year for a given set of financial transactions. The results should be rounded to two decimal places.

Additional information

  • The financials table contains the columns transaction_date (DATE) and amount (NUMERIC).
  • The growth_percentage is calculated as ((current year's revenue - previous year's revenue) / previous year's revenue) * 100.
  • If there is no previous year's revenue for a given year, the previous_revenue and growth_percentage should be NULL.
  • Order the results by year in ascending order.

Examples

Example 1:

Input:

financials
amounttransaction_date
1000002020-01-15
1500002020-06-30
2000002020-12-15
1800002021-03-20
2200002021-07-10
2500002021-12-31
2400002022-02-28
2800002022-08-15
3000002022-12-20

Output:
current_revenuegrowth_percentageprevious_revenueyear
450000nullnull2020
65000044.444500002021
82000026.156500002022
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →