Other related articles:

Recently viewed articles:

SQL AVG Function

SQL not only retrieves individual pieces of data from the database, but it also can summarize the database contents. Suppose if you want to find out the average for a column or expression in a results set, you just need to use the SQL AVG() function. SQL AVG() function ignores NULL values in column under consideration.

Example:

The following SQL AVG Function returns average salary for all employees in employee table:

SELECT AVG(salary) FROM employee;

Output:
sql avg 1

Example 2:

The following is a query that uses SQL AVG Function to select employees whose salary is greater than the average.

SELECT full_name, salary
FROM employee
WHERE salary > (SELECT AVG(salary) FROM employee);

Output:
sql avg 2

Example 3:

The following uses SQL AVG Function to retrieve deptno and AVG (salary) for each department:

SELECT dept_no, AVG(salary)
FROM employee
GROUP BY dept_no;

Output:
sql avg 3