Second-Highest Distinct Salary
Problem statement
The employees table contains one row per employee with an optional salary.
Return exactly one row and one column named second_highest_salary. Its value is the second-highest distinct non-NULL salary. If fewer than two distinct non-NULL salaries exist, return NULL.
Table schema
MySQLPostgreSQLPandas
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.
| Column | Type | Nullable | Description |
|---|---|---|---|
| employee_idPK | Integer | No | — |
| salary | Integer | Yes | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| second_highest_salary | Integer | Yes | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
employee_idis a unique integer.salaryis an integer orNULL.- Duplicate salary values share the same rank.
- The result always contains exactly one row.