# AVG

In SQL, the ** AVG()** function is an aggregate function used to calculate the average (mean) value of a specified column or a set of numerical values. The

**function computes the sum of all values in the specified column and then divides the sum by the number of rows.**

`AVG()`

## Basic syntax

The basic syntax of the ** AVG()** function is as follows:

```
SELECT AVG(column_name)
FROM table_name
WHERE condition
```

: This calculates the average value of the non-NULL values in the specified`AVG(column_name)`

.`column_name`

: This is the name of the table from which you want to retrieve the data.`table_name`

: This is an optional condition that specifies which rows to include in the average calculation.`condition`

## Examples

**Calculating Average Salary**

Consider a table named ** employees** with a

**column. To calculate the average salary of all employees, you can use:**

`salary`

```
SELECT AVG(salary)
FROM employees
```

This query will return the average salary of all employees in the ** employees** table.

**Calculating Average Based on a Condition**

To calculate the average salary of employees in the 'IT' department, you can use:

```
SELECT AVG(salary)
FROM employees
WHERE department = 'IT'
```

This query will return the average salary of employees who belong to the 'IT' department.

## Remember

The ** AVG()** function ignores

**values in the specified column when calculating the average. If a column contains**

`NULL`

**values, they are excluded from the calculation.**

`NULL`