Beginner

427. JOIN and AVG

Learn how AVG can calculate average values across related records.

📘 Lesson 427 of 728 ⏱ 11 min 🎯 Intermediate

AVG calculates the arithmetic mean of numeric values and can be used with joined tables to calculate averages for related groups.

Average values are frequently used to measure customer spending, order values, salaries, processing times, and performance metrics.

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;

AVG with JOIN is useful for customer analysis, sales performance, financial reporting, and operational metrics.

  • AVG calculates an arithmetic mean.
  • AVG can be used with joined tables.
  • GROUP BY calculates averages for each group.
  • NULL values are generally ignored by AVG.
  • Join duplication can affect average calculations.
Can AVG be used with JOIN?

Yes. AVG can calculate average values from data returned by a JOIN.

What can cause an incorrect average after a JOIN?

Incorrect join relationships or duplicated rows can change the set of values included in the average.

Have you finished this lesson?

Introduction to SQL – All Lessons