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