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() Syntax

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


SELECT AVG(column_name1) FROM table_name;


Search Keys

  • sql average function
  • average in sql
  • sql average
  • tsql average
  • sql average of sum
  • sql server average
  • sql average count
  • sql server average function
  • sql server average count
  • sql average date

Sample Database Table - Employee

ID EmpName Designation Dept JoinYear Salary
1 Pandurengan Mobile Database SQL Server 2013 11450.7
2 Chandra Data Mining ASP.Net 2013 15440
3 Azaghu Varshith Project Manager JQuery 2012 16070.2
4 Padmavathi Database Security C#.Net 2012 17540
5 Dharan Manager Java 2014 20480
6 Geetha Database Designer ASP.Net 2012 19430.9
7 Rishi Keshan Mobile Database MS Access 2015 3470.7
8 Devi Mai SQL Mining PHP 2012 13760
9 Vinoth Kumar Data Mining Java 2012 5780
10 Harish Karthik Big Data C#.Net 2013 17120
11 Sakunthala Information Tech C#.Net 2012 9560
12 Keshavan Data Mining C#.Net 2013 5990.3

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
13007.733

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
6200.25

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 17435.45
C#.Net 12552.575
Java 13130
JQuery 16070.2
MS Access 3470.7
PHP 13760
SQL Server 11450.7

Search Keys

  • sql query for average
  • sql query average
  • select average sql
  • sql find average
  • aggregate functions in sql
  • sql aggregate functions
  • aggregate query
  • sql aggregate functions examples
  • aggregate sql functions
  • sql aggregate functions with examples