Top SQL Questions

Scott G

Find 5th Highest Salary

This question asks for the 5th highest salary from the "Employees" table. The example input is a table with id, name, and salary columns, and the example output is a table with a salary column.

Problem

Write a SQL query to find the 5th highest salary from the "Employees" table.
Example input:
| id | name  | salary |
|----|-------|--------|
| 1  | John  | 1000   |
| 2  | Jane  | 2000   |
| 3  | Bob   | 3000   |
| 4  | Alex  | 4000   |
| 5  | David | 5000   |
Example output:
| salary |
|--------|
| 4000   |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by AskAI
SELECT salary FROM Employees ORDER BY salary DESC LIMIT 4, 1;

/*

The solution above is optimal because it uses the LIMIT clause to limit the number of rows returned by the query.

*/

A.I. Evaluation of the Solution

The solution above is optimal because it uses the LIMIT clause to limit the number of rows returned by the query.

Evaluated at: 2023-02-02 23:06:04

Community solutions:

Check these solutions from our community and artificial intelligence:
The candidate's solution correctly finds the 5th highest salary from the "Employees" table. The solution uses a with statement to create a rating table, which is then used to select the 5th highest salary. This is a valid approach and the solution correctly solves the problem.
The candidate's solution correctly finds the 5th highest salary from the "Employees" table. The solution uses the correct SQL syntax and demonstrates a good understanding of the problem.
The candidate's solution correctly finds the 5th highest salary from the "Employees" table. The solution uses the correct SQL syntax and demonstrates a good understanding of the problem.