Beginner

597. JOIN with AVG

Use AVG with JOINs to calculate average values across related records.

📘 Lesson 597 of 728 ⏱ 13 min 🎯 Intermediate

AVG calculates the arithmetic mean of numeric values from rows selected by the query. After a JOIN, it can calculate averages for each related group.

Average transaction value, salary, order amount, and processing time are common analytical measures.

Calculate the average order value for each customer.

SQL
SELECT
    c.CustomerName,
    AVG(o.OrderAmount) AS AverageOrderValue
FROM Customers c
INNER JOIN Orders o
    ON c.CustomerID = o.CustomerID
GROUP BY
    c.CustomerName;

Used in customer analytics, sales performance, financial analysis, and operational reporting.

  • AVG calculates the arithmetic mean.
  • NULL values are generally ignored by AVG.
  • JOIN determines the related records included.
  • GROUP BY calculates averages per entity.
  • Check whether the JOIN level matches the business requirement.
How can AVG be used with JOIN?

AVG can calculate the average value of related rows after the tables are joined and grouped.

Does AVG include NULL values?

In standard SQL, AVG ignores NULL values when calculating the average.

Have you finished this lesson?

Introduction to SQL – All Lessons