Second-Highest Distinct Salary
Problem statement
The table employees contains one row per employee with an integer salary. Find the second-highest distinct salary.
Return exactly one row with the column second_highest_salary. If fewer than two distinct salaries exist, return NULL in that row.
Table: employees
| Column | Type | Meaning |
|---|---|---|
employee_id | integer | Unique employee identifier |
salary | integer | Employee salary |
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 | No | — |
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
- The table may be empty.
employee_idis unique and non-null.salaryis non-null and is between-10^9and10^9.- Equal salaries share a rank.