Third Highest Salary

HardSQLDatabaseSorting

Description

Write a SQL query to return the third highest distinct salary from the employees table as a single value named third_highest. If it does not exist, return null. **Output columns (in order):** third_highest

Table:employees
ColumnType
idINT
salaryINT

Examples

Input:CREATE TABLE employees (id INT, salary INT); INSERT INTO employees VALUES (1,100),(2,200),(3,300),(4,400);
Output:200
Explanation:

Counting how many distinct salaries are greater than or equal to each value pinpoints the one ranked third from the top.

Input:CREATE TABLE employees (id INT, salary INT); INSERT INTO employees VALUES (1,50),(2,50),(3,40),(4,30),(5,20);
Output:30
Explanation:

Counting how many distinct salaries are greater than or equal to each value pinpoints the one ranked third from the top.

Input:CREATE TABLE employees (id INT, salary INT); INSERT INTO employees VALUES (1,500),(2,500),(3,400),(4,300);
Output:300
Explanation:

Counting how many distinct salaries are greater than or equal to each value pinpoints the one ranked third from the top.

Constraints

  • Use standard SQL (SQLite).

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.