The AVG() function returns the average of an expression when using SELECT.

Structure

SELECT AVG(EXPRESSION)
FROM TABLE
WHERE [CONSTRAINTS]

Example

Let’s say we want to find the average salary of Software Engineers in Company A. We will use two tables: Positions and Salaries. Here’s how to go about it:

SELECT p.position_name, AVG(s.salary) average_salary from salaries s
JOIN POSITIONS p ON p.ID = s.positions_id
WHERE p.position_name = 'Software Engineer'