SQL AVG() Function

SQL AVG() Function


The SQL AVG() is a function, and return average value of a table column from query result.

The SQL AVG() function is supports only numeric column.

It can be used in SQL SELECT statement as well in SQL WHERE clause.



Sql avg function using sql server average of sum, average count, sql server average function, sql server average count.

SQL AVG() Syntax

The below syntax is used to select specific column from the specific table.


SELECT AVG(column_name1) FROM table_name;

Sample Database Table - Employee

ID EmpName Designation Dept JoinYear Salary
1 Chandra Data Mining ASP.Net 2013 15440
2 Padmavathi Database Security C#.Net 2012 17540
3 Dharan Manager Java 2014 20480
4 Rishi Keshan Mobile Database MS Access 2015 3470.7
5 Vinoth Kumar Data Mining Java 2012 5780
6 Sakunthala Information Tech C#.Net 2012 9560

SQL AVG() Example

The following SQL SELECT statement find the average salary of all employees from the "Employee" table:


SELECT 
AVG(Salary) As 'Average Salary' 
FROM Employee;

The result of above query is:

Average Salary
12045.116

SQL AVG() Example - Using SQL WHERE Clause

The following SQL SELECT statement find the average salary of all employees, which has salary less than 10000 from the "Employee" table:


SELECT 
AVG(Salary) As 'Average Salary' 
FROM Employee 
WHERE Salary < 10000;

The result of above query is:

Average Salary
6270.233

SQL AVG() Example - Using Group By Clause

The following SQL SELECT statement find the average salary by grouping "Dept" column of all employees from the "Employee" table:


SELECT 
Dept, AVG(Salary) As 'Average Salary' 
FROM Employee 
GROUP BY Dept;

The result of above query is:

Dept Average Salary
ASP.Net 15440
C#.Net 13550
Java 13130
MS Access 3470.7


Sql server avg function using sql query for average, sql aggregate functions with examples.