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.

Practice it on a real question

All Aggregation questions

Practice on your iPhone

Query Dojo for iPhone has 85 interview questions, timed mock interviews and a tile builder, so you can write queries without a keyboard.

Get the app