SQL AVG() Function

AVG() Function:-  SQL AVG function is used to find out the average of a filed in various records. In the SQL AVG function, NULL values are ignored.


SYNTAX:-

SELECT AVG(column_name)
FROM table_name ;

To understand AVG function, consider a Persons table, which is having the following records:_

EXAMPLE:- Now based on the above table you want to calculate the average of all the Salary of the persons, then you can do so by using the following Query:- 

SELECT AVG(Salary) As AverageSalary
FROM Persons ;

OUTPUT:-

You can use the WHERE Clause with AVG function as follows:-

EXAMPLE:-

SELECT AVG (Salary) As AverageSalary
FROM Persons
WHERE  Age >24 ;

OUTPUT:-


You can take an Average of various records using the GROUP BY clause.

EXAMPLE:- 

SELECT FirstName, AVG(Salary)
FROM Persons 
GROUP BY FirstName ;

OUTPUT:-



Comments

Popular posts from this blog

ASP.NET Overview

SQL AND ,OR, NOT Operators

SQL Joins