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| Column | Type |
|---|---|
| id | INT |
| salary | INT |
Examples
Input:
CREATE TABLE employees (id INT, salary INT); INSERT INTO employees VALUES (1,100),(2,200),(3,300),(4,400);Output:
200Explanation:
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:
30Explanation:
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:
300Explanation:
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).