101
0/304
Loading content...
Your analytics team stores compensation values in an Employee table:
You are also given a one-row parameter table:
Return the n-th highest distinct salary across all employees.
Important details:
Solve this in both:
employee:
| id | salary |
|----|--------|
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
salary_request:
| n |
|---|
| 2 |[
{"nthHighestSalary": 200}
]Distinct salaries in descending order are [300, 200, 100], so rank 2 is 200.
employee:
| id | salary |
|----|--------|
| 1 | 100 |
| 2 | 100 |
| 3 | 80 |
salary_request:
| n |
|---|
| 1 |[
{"nthHighestSalary": 100}
]Repeated salaries do not create new ranks. The highest distinct salary is 100.
employee:
| id | salary |
|----|--------|
| 1 | 500 |
salary_request:
| n |
|---|
| 3 |[
{"nthHighestSalary": null}
]Only one distinct salary exists, so the third distinct salary is not available.
Constraints