SQL AVG Function

Friday, December 9, 2011

tags SQL

The SQL AVG() function returns the average value of a table's column/field.

Employees Table

1000John Smith40
1001Fred White27
1002Jane Scott53
1003Samuel Williams31

In this example, we want to find the average age of an employee.


SELECT AVG(column_name)
FROM Table

SELECT AVG(age) as [Average Age]
FROM employees


SELECT employeeID, employeeName FROM employees
WHERE age > (SELECT AVG(age) from employees)


Average Age

1000John Smith
1002Jane 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

Head First SQL: Your Brain on SQL A Learners Guide SQL Cookbook