Second Highest Salary
Problem statement
The table employees contains salary values. Find the second-highest distinct, non-NULL salary.
Equal salaries share one rank. Ignore rows whose salary is NULL.
Return exactly one row and one column named second_highest_salary. If fewer than two distinct non-NULL salaries exist, that row must contain 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
Only the salary column is needed for this query.
| Column | Type | Nullable | Description |
|---|---|---|---|
| salary | Integer | Yes | Employee salary; NULL denotes an unknown salary. |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| second_highest_salary | Integer | Yes | Second-highest distinct known salary, or NULL when absent. |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
employeescontains between0and2000rows.- Each known salary is an integer from
0through10^9, inclusive. - The table may contain duplicate salary values and
NULLsalaries.