---
title: "How do you use the AVG() function to calculate the average value of a column in SQL?"  
description: "How do you use the AVG() function to calculate the average value of a column in SQL?"  
author: "Revati S Misra"  
published: 2023-06-30  
updated: 2023-07-01  
canonical: https://www.mindstick.com/forum/158909/how-do-you-use-the-avg-function-to-calculate-the-average-value-of-a-column-in-sql  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# How do you use the AVG() function to calculate the average value of a column in SQL?

How do you use the [AVG](https://www.mindstick.com/articles/445/aggregate-function-in-sql-server)() [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) to [calculate the average](https://www.mindstick.com/forum/159301/write-a-mongodb-aggregation-query-to-group-and-calculate-the-average-of-a-field-in-a-collection) [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) of a [column in SQL](https://www.mindstick.com/forum/34026/how-to-insert-values-to-identity-column-in-sql-server)?

## Replies

### Reply by Aryan Kumar

Sure. The AVG() function in [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) is used to calculate the average value of a [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server). The syntax for the AVG() function is:

SQL

```plaintext
AVG(column_name)
```

- `column_name` is the name of the column that you want to calculate the average of.

The AVG() function will return the average value of all the non-NULL values in the column. For example, the following query will return the average salary of all employees in the `employees` table:

SQL

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

The AVG() function can also be used with the DISTINCT keyword to calculate the average of unique values in a column. For example, the following query will return the average salary of all employees in the `employees` table, but it will only consider each salary once:

SQL

```plaintext
SELECT AVG(DISTINCT salary)
FROM employees;
```

The AVG() function is a versatile tool that can be used to calculate the average value of a column in SQL. It can be used to find the average salary of employees, the average price of products, or the average rating of movies.

Here are some other examples of how the AVG() function can be used:

- To calculate the average age of customers.
- To calculate the average number of items in an order.
- To calculate the average time it takes to complete a task.

The AVG() function is a powerful tool that can be used in a variety of ways. If you are working with data in SQL, then the AVG() function is a tool that you should definitely know about.


---

Original Source: https://www.mindstick.com/forum/158909/how-do-you-use-the-avg-function-to-calculate-the-average-value-of-a-column-in-sql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
