Easy Aggregates and GROUP BY Employees database

Average salary with AVG

Question

Show the average salary of all employees, rounded to a whole number.

employeesid, name, salary, department_id, manager_id, hired_on
departmentsid, name, city

Your query

Ctrl+Enter to run

Result

Press Run to see your query's result, or Check answer to compare it with the expected result.

Expected result

average_salary
6367

Rows can come in any order. Column names do not have to match.

Hint

AVG() gives the average and ROUND(value) rounds it.

Show the solution
solution.sql Run this code
SELECT ROUND(AVG(salary)) AS average_salary
FROM employees;

Why it works

AVG adds up the salaries and divides by the number of non-NULL salaries. ROUND with one argument rounds to zero decimal places.

Common mistake

In some databases, AVG on an integer column returns an integer and cuts off the decimals. In SQLite AVG always returns a real number, so rounding is up to you.

Want to try the query on MySQL or PostgreSQL? Open it in the SQL Online Compiler or SQLite Online.