Find Employees Who Make More Than Average Salary

This technical problem involves writing a SQL query to find employees who make more than the average salary.

Problem

Given a table of employees and their salaries, write a SQL query to find the employees who make more than the average salary.
Example input:
| id | name  | salary |
|----|-------|--------|
| 1  | John  | 1000   |
| 2  | Jane  | 2000   |
| 3  | Bob   | 3000   |
Example output:
| id | name  | salary |
|----|-------|--------|
| 2  | Jane  | 2000   |
| 3  | Bob   | 3000   |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT id, name, salary
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);

/*

The solution above is optimal because it uses a subquery to find the average salary of all employees, and then uses that value to filter the employees table.

*/

A.I. Evaluation of the Solution

The solution above is optimal because it uses a subquery to find the average salary of all employees, and then uses that value to filter the employees table.

Evaluated at: 2022-11-13 06:15:48