Average Salary by Department

This technical problem deals with writing a query that returns the average salary of employees in each department. The given table includes information on the department, employee, and salary. The expected output is a table that lists the department and the average salary for that department.

Problem

Given a table with information on employees, write a query that returns the average salary of employees in each department.
Example input:
| department | employee | salary |
|------------|----------|--------|
| IT         | John     | 50000  |
| IT         | Jane     | 60000  |
| HR         | Joe      | 40000  |
| HR         | Amy      | 45000  |
| Finance    | Bob      | 70000  |
Example output:
| department | average_salary |
|------------|----------------|
| IT         | 55000          |
| HR         | 42500          |
| Finance    | 70000          |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT department, AVG(salary) AS average_salary
FROM employees
GROUP BY department;

A.I. Evaluation of the Solution

This solution is complete and solves the problem. The approach is straightforward and easy to follow.

Evaluated at: 2022-11-20 00:16:27