N-th Highest Salary
Updated
Problem statement
The employees table lists the staff of one bank branch, one row per employee, with each person's yearly salary. Several employees can earn exactly the same amount. The one-row table rank_request holds a positive integer n.
Write a query that returns the n-th highest salary in employees. Salaries are ranked as values, so equal salaries count once: the highest salary is rank 1, the next smaller amount is rank 2, and so on, however many people earn each amount.
Return exactly one row with one column, nth_highest_salary. When the table has fewer than n different salaries, return that one row with NULL (None in Pandas).
Table schema
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 of the branch.
| Column | Type | Nullable | Description |
|---|---|---|---|
| employee_idPK | Integer | No | Unique employee ID. |
| employee_name | Text | No | The employee's name. |
| salary | Integer | No | Yearly salary. |
rank_request
Exactly one row: which salary rank to return.
| Column | Type | Nullable | Description |
|---|---|---|---|
| nPK | Integer | No | The salary rank to find, 1 for the highest. |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| nth_highest_salary | Integer | Yes | — |
Row order: any order is accepted. Numeric tolerance: 0.
Constraints
- The
employeestable has between1and1000rows. employee_idvalues are unique, with1 <= employee_id <= 100000.employee_namehas 1 to 40 characters.1 <= salary <= 1000000- The
rank_requesttable has exactly one row, with1 <= n <= 1000.
More Bank of America Onsite Interview questions
- Centered Star PyramidONSITE INTERVIEW · Seen Nov 2025
- Employees Without a ManagerONSITE INTERVIEW · Seen Nov 2025
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2025
- N-th Fibonacci NumberONSITE INTERVIEW · Seen Nov 2025
- Reverse Each Word in a SentenceONSITE INTERVIEW · Seen Nov 2025
- Second Highest SalaryONSITE INTERVIEW · Seen Nov 2025
- Three Numbers That Add Up to a TargetONSITE INTERVIEW · Seen Apr 2025
- Duplicate RowsONSITE INTERVIEW · Seen Oct 2023
- Factorial of a NumberONSITE INTERVIEW · Seen Oct 2023
- Palindrome String CheckONSITE INTERVIEW · Seen Sep 2023
Similar questions at other companies
- Daily USD Totals with Effective-Dated Exchange RatesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Most Recent Order for Each CustomerCapgemini · ONSITE INTERVIEWCapgemini interview questions
- Tenth-Highest Distinct SalaryInfosys · ONSITE INTERVIEWInfosys interview questions
- Fifth Highest Salary In A DepartmentZS · ONSITE INTERVIEWZS interview questions
- In-Memory Database QueriesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Order Book Data ValidationJane Street · ONSITE INTERVIEWJane Street interview questions
- Nth-Highest Distinct Salary Without Ranking FunctionsMastercard · ONSITE INTERVIEWMastercard interview questions
- Contest Participants with Long Totals and Short QuestionsThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
- First Order per Merchant per DateAmazon · ONSITE INTERVIEW
- Block Transaction Count TrendsChainalysis · ONSITE INTERVIEWChainalysis interview questions