3rd Highest Salary in a Table

To find the third highest salary in a table, you can use a SQL query. For example, given the following table: | ID | Name | Salary | |---- |-------|--------| | 1 | John | 1000 | | 2 | Jane | 2000 | | 3 | Joe | 3000 | | 4 | Sarah | 4000 | | 5 | Dave | 5000 | The third highest salary would be Joe's, with a salary of 3000.

Problem

Given a table of data, write a SQL query to find the 3rd highest salary.
Example input:
| ID | Name  | Salary |
|----|-------|--------|
| 1  | John  | 1000   |
| 2  | Jane  | 2000   |
| 3  | Joe   | 3000   |
| 4  | Sarah | 4000   |
| 5  | Dave  | 5000   |
Example output:
| ID | Name  | Salary |
|----|-------|--------|
| 3  | Joe   | 3000   |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT TOP 1 Salary
FROM Employee
ORDER BY Salary DESC
OFFSET 2 ROWS
FETCH NEXT 1 ROWS ONLY;

/*

The above solution is optimal because it uses the TOP and OFFSET keywords to return the 3rd highest salary.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and uses the optimal approach to return the 3rd highest salary.

Evaluated at: 2022-11-23 06:16:29