Skip to main content

Year-Over-Year (YOY) Growth in SQL: The Ultimate Guide with Examples

ยท 4 min read
Data Product Executive

Introductionโ€‹

Year-over-Year (YOY) growth is a key metric used to measure business performance by comparing values from one period to the same period one year earlier. It eliminates seasonal fluctuations and highlights long-term trends.

Businesses rely on YOY growth to track revenue, customer base, profit margins, and market expansion. Understanding YOY growth helps companies make data-driven decisions and adjust their strategies based on long-term performance.


YOY Growth Formulaโ€‹

The standard formula for calculating YOY growth is:

YOY Growth (%) = ((Current Year Value - Previous Year Value) / Previous Year Value) ร— 100

Example Calculation:โ€‹

A company's revenue in 2023 was $1,200,000, compared to $1,000,000 in 2022. The YOY growth is:

SELECT 2023 AS Year, 1200000 AS Revenue,
1000000 AS Prev_Year_Revenue,
((1200000 - 1000000) / 1000000) * 100 AS YOY_Growth;

Output:โ€‹

YearRevenue ($)Prev Year Revenue ($)YOY Growth (%)
20231,200,0001,000,00020.0%

Data Model and Sample Dataโ€‹

To analyze YOY growth effectively, we use the following relational schema:

Sample Input Dataโ€‹

YearRevenue ($)CustomersNet Profit ($)Market Share (%)
20221,000,0005,000200,00010.0
20231,200,0006,000250,00012.0
20241,440,0007,200312,50014.4

Practical Use Casesโ€‹

1. Revenue Growthโ€‹

Tracking revenue growth is essential for understanding business performance over time.

SQL Query:โ€‹

SELECT year, revenue,
LAG(revenue, 1) OVER (ORDER BY year) AS prev_year_revenue,
((revenue - LAG(revenue, 1) OVER (ORDER BY year)) / LAG(revenue, 1) OVER (ORDER BY year)) * 100 AS YOY_Growth
FROM financials;

Output:โ€‹

YearRevenue ($)Prev Year Revenue ($)YOY Growth (%)
20221,000,000NULLNULL
20231,200,0001,000,00020.0%
20241,440,0001,200,00020.0%

2. Customer Growthโ€‹

Analyzing YOY customer growth helps businesses measure expansion.

SQL Query:โ€‹

SELECT year, customers,
LAG(customers, 1) OVER (ORDER BY year) AS prev_year_customers,
((customers - LAG(customers, 1) OVER (ORDER BY year)) / LAG(customers, 1) OVER (ORDER BY year)) * 100 AS YOY_Growth
FROM financials;

Output:โ€‹

YearCustomersPrev Year CustomersYOY Growth (%)
20225,000NULLNULL
20236,0005,00020.0%
20247,2006,00020.0%

3. Profitability and Cost Efficiencyโ€‹

Understanding profitability trends helps assess financial health.

SQL Query:โ€‹

SELECT year, net_profit,
LAG(net_profit, 1) OVER (ORDER BY year) AS prev_year_profit,
((net_profit - LAG(net_profit, 1) OVER (ORDER BY year)) / LAG(net_profit, 1) OVER (ORDER BY year)) * 100 AS YOY_Growth
FROM financials;

Output:โ€‹

YearNet Profit ($)Prev Year Profit ($)YOY Growth (%)
2022200,000NULLNULL
2023250,000200,00025.0%
2024312,500250,00025.0%

4. Market Share and Performanceโ€‹

Evaluating market share growth helps measure competitiveness.

SQL Query:โ€‹

SELECT year, market_share,
LAG(market_share, 1) OVER (ORDER BY year) AS prev_year_share,
((market_share - LAG(market_share, 1) OVER (ORDER BY year)) / LAG(market_share, 1) OVER (ORDER BY year)) * 100 AS YOY_Growth
FROM financials;

Output:โ€‹

YearMarket Share (%)Prev Year Share (%)YOY Growth (%)
202210.0NULLNULL
202312.010.020.0%
202414.412.020.0%

YOY vs. MoM vs. CAGRโ€‹

While YOY growth is valuable for annual comparisons, other metrics serve different purposes:

  1. Month-over-Month (MoM): Measures short-term growth between consecutive months
  2. Compound Annual Growth Rate (CAGR): Calculates the average annual growth rate over multiple years

How to Calculate YOY Growth in SQLโ€‹

SQL provides powerful tools for YOY calculations:

  1. Window Functions: Use LAG() to access previous year's values
  2. Self Joins: Join a table with itself to compare years
  3. CTEs: Create temporary result sets for complex calculations

Common Mistakes and Best Practicesโ€‹

  1. Handle NULL Values: Use COALESCE or ISNULL for first-year calculations. Learn more about handling NULL values in our comprehensive COALESCE guide.
  2. Data Quality: Ensure consistent date formats and complete datasets
  3. Seasonal Adjustments: Consider seasonal patterns in your analysis
  4. Percentage Formatting: Format results appropriately for reporting

Visualizing YOY Growth with a Database Schemaโ€‹

Try these examples yourself using RunSQL's SQL playground. Our platform makes it easy to:

  1. Create tables using DBML
  2. Import sample data
  3. Run and share SQL queries
  4. Visualize results

Conclusionโ€‹

YOY growth analysis is crucial for business intelligence and decision-making. By mastering SQL calculations and understanding best practices, you can effectively track and analyze performance metrics over time.

Ready to practice YOY calculations? Try RunSQL for free and experiment with these examples in a live environment.