Third-Highest Known Salary
Problem statement
Each row of employees describes one person: emp_id identifies them, emp_name is their name, and salary is their pay. salary is NULL when the pay has not been entered yet.
Work out which salary ranks third from the top. Ignore missing pay, and treat equal salaries as a single value: with known salaries 90, 90, 70, 70 and 40, the ranking is 90, 70, 40, so the answer is 40.
Your result must have a single row and a single column, third_highest_salary. When fewer than three different salaries are known, put NULL in that row.
Table schema
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
employees
One row per employee. salary is NULL when the pay is not known.
| Column | Type | Nullable | Description |
|---|---|---|---|
| emp_idPK | Integer | No | — |
| emp_name | Text | No | — |
| salary | Integer | Yes | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| third_highest_salary | Integer | Yes | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- The
employeestable has from0to1000rows. emp_idis unique and1 <= emp_id <= 10^6.salaryisNULLor a whole number with1 <= salary <= 10^9. Salaries can repeat.emp_nameis one uppercase English letter followed by 0 to 19 lowercase English letters. Names can repeat.emp_idandemp_nameare neverNULL.