12. 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.
Essential
SQL 0/33
Spark 0/20
Snowflake 0/22
Python 0/24
Need more practice in this area? Explore more questions →
OpenAI
Revolut
Accenture
Adobe
Google
LinkedIn
Samsung
Datadog
Wix
Dropbox
Meta
Hulu
Uber
X
DoorDash
Anthropic
Amazon
ActivisionBlizzard
Vercel
Crypto.Com
Zscaler
DeutscheBank
Apple
GoDaddy
GitLab
BMW
PayPal
Snowflake
AMD
Twilio
Atlassian
JPMorgan
NVIDIA
IBM
Databricks
Coinbase
Cisco
Robinhood
Twitter
Microsoft
Palantir
Netflix
VMware
Cloudflare
Stripe
Lyft
Salesforce
GitHub
Bloomberg
Airbnb
Walmart
SAP
HashiCorp
Instacart
Mastercard
Intel
Visa
Tesla