AVG() Function in MySQL (original) (raw)

Last Updated : 28 Mar, 2026

The AVG() function in MySQL is used to calculate the average (mean) value of a specified numeric expression or column. It helps summarize data by returning a single average value from multiple rows.

**Syntax :

AVG(expression)

Working with the MySQL AVG() Function

The following examples show how the AVG() function works with different columns and conditions. First, we will create a demo table on which the AVG() function will be applied:

Screenshot-2026-03-28-113709

students Table

Example 1: Basic AVG() Usage

This example calculates the average marks of all students. It provides a quick summary of overall performance.

**Query:

SELECT AVG(marks) AS average_marks FROM students;

**Output:

Screenshot-2026-03-28-120557

Example 2: AVG() with Multiple Columns

This example calculates the average of more than one numeric column. It helps compare different metrics in a single query.

**Query:

SELECT AVG(marks) AS avg_marks, AVG(age) AS avg_age FROM students;

**Output:

Screenshot-2026-03-28-120637

Example 3: AVG() with Subquery

This example filters students based on the average marks. It shows how AVG() can be used inside a subquery for comparison.

**Query:

SELECT * FROM students WHERE marks > (SELECT AVG(marks) FROM students);

**Output:

Screenshot-2026-03-28-120729

Example 4: AVG() with GROUP BY

This example calculates the average marks for each department. It helps analyze performance across different groups.

**Query:

SELECT department, AVG(marks) AS avg_marks FROM students GROUP BY department;

**Output:

Screenshot-2026-03-28-120821