Nth-Highest Distinct Salary Without Ranking Functions
Problem statement
Return the Nth-highest distinct salary without using ranking window functions such as RANK, DENSE_RANK, or ROW_NUMBER.
The desired positive integer N is supplied in query_params.
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
| Column | Type | Nullable | Description |
|---|---|---|---|
| employee_idPK | Integer | No | — |
| employee_name | Text | No | — |
| salary | Decimal | No | — |
query_params
Contains exactly one row with param_id 1.
| Column | Type | Nullable | Description |
|---|---|---|---|
| param_idPK | Integer | No | — |
| n | Integer | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| salary | Decimal | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
query_paramscontains exactly one row withparam_id = 1and positiven.- Duplicate salary values occupy one position.
- Return no rows when fewer than N distinct salaries exist.