The SQL AVG() function returns the average value of a table's column/field.
Employees Table
employeeID | employeeName | age |
1000 | John Smith | 40 |
1001 | Fred White | 27 |
1002 | Jane Scott | 53 |
1003 | Samuel Williams | 31 |
In this example, we want to find the average age of an employee.
Syntax
SELECT AVG(column_name)
FROM Table |
Example
SELECT AVG(age) as [Average Age]
FROM employees
Or
SELECT employeeID, employeeName FROM employees
WHERE age > (SELECT AVG(age) from employees) |
Results
employeeID | employeeName |
1000 | John Smith |
1002 | Jane Scott |
The SQL AVG function can return the average of a column or can be used with WHERE to filter the rows for the
specific range of data that you need.
Did you find the page informational and useful? Share it using one of your favorite social sites.
Recommended Books & Training Resources