Find the Top 5 Employees with the Highest Salaries

To find the top 5 employees with the highest salaries, you can write a SQL query that orders the employees by salary in descending order and then limits the result set to the first 5 employees.

Problem

Given a table of employee data, write a SQL query to find the top 5 employees with the highest salaries.
Example input:
| employee_id | name  | salary |
| ------------|-------|--------|
| 1           | John  | 100000 |
| 2           | Jane  | 120000 |
| 3           | Smith | 90000  |
Expected output:
| employee_id | name  | salary |
| ------------|-------|--------|
| 2           | Jane  | 120000 |
| 1           | John  | 100000 |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT employee_id, name, salary
FROM employee
ORDER BY salary DESC
LIMIT 5;

/*

The solution above is optimal because it uses the ORDER BY and LIMIT clauses to sort the table by salary in descending order and then limit the results to the top 5 salaries.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a good understanding of SQL. The candidate has correctly used the ORDER BY and LIMIT clauses to sort the table by salary in descending order and then limit the results to the top 5 salaries.

Evaluated at: 2022-11-25 00:16:13