Medium
SQL-W03sqlNth Highest Salary Per Dept
Problem
From `employees(dept_id, name, salary)` return the **2nd highest** salaried employee in each dept (NULL if dept has only one employee).
Input
employees
Output
dept_id, name, salary
Constraints
1 ≤ rows ≤ 10^5
Sample input
see prompt
Sample output
...
Explanation
Use DENSE_RANK to handle ties — the 2nd-highest 'rank' may have ties.
window-fndense-ranktop-n-per-group@Amazon
Visible test cases
in: see
out: ...
Your solution — run it, use AI if stuck
sql
