Intermediate · Lesson 2 of 20

SUM and AVG

SUM adds up all values in a column. AVG calculates the average.

Total payroll:

SELECT SUM(salary) FROM employees;

Average salary:

SELECT AVG(salary) FROM employees;

Combine with WHERE:

SELECT AVG(salary) FROM employees
WHERE department_id = 1;

These ignore NULL values automatically.

Check your understanding

What is the average salary across all employees?

Examples run on the employees sample database. Open any of them in the playground to experiment.