Average Employee Salary by Department

This technical problem involves writing a SQL query to find the average salary of employees by department. The example input table includes columns for department, first name, last name, and salary. The expected output is a table with columns for department and average salary.

Problem

Given a table of employee data, write a SQL query to find the average salary of employees by department.
Example input:
+------------+-------------+-------------+
| department | first_name  | last_name   |
+------------+-------------+-------------+
| IT         | John        | Doe         |
| HR         | Jane        | Smith       |
| Sales      | Jack        | Black       |
| IT         | Ashley      | Johnson     |
| Marketing  | Jessica     | Wong        |
+------------+-------------+-------------+
Example output:
+------------+-----------------+
| department | average_salary  |
+------------+-----------------+
| IT         | 15000           |
| HR         | 20000           |
| Sales      | 25000           |
| Marketing  | 30000           |
+------------+-----------------+

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-23 04:16:24