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
financialstable contains the columnstransaction_date(DATE) andamount(NUMERIC). - The
growth_percentageis 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_revenueandgrowth_percentageshould beNULL. - Order the results by year in ascending order.
Examples
Example 1:
Output:
Input:
| financials | |
|---|---|
| amount | transaction_date |
| 100000 | 2020-01-15 |
| 150000 | 2020-06-30 |
| 200000 | 2020-12-15 |
| 180000 | 2021-03-20 |
| 220000 | 2021-07-10 |
| 250000 | 2021-12-31 |
| 240000 | 2022-02-28 |
| 280000 | 2022-08-15 |
| 300000 | 2022-12-20 |
| current_revenue | growth_percentage | previous_revenue | year |
|---|---|---|---|
| 450000 | null | null | 2020 |
| 650000 | 44.44 | 450000 | 2021 |
| 820000 | 26.15 | 650000 | 2022 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
OpenAI