Skip to main content

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

Data Product Executive
Published on March 1, 2025

Master Year-over-Year (YOY) growth calculations in SQL with practical examples, common use cases, and best practices. Learn how to track business performance metrics effectively using SQL window functions.

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

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. If several teams report YOY growth, defining it once in a semantic layer keeps everyone's numbers consistent.

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