Your question is Second and Nth Highest Values. Start with the requirements and the one table on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
How would you write a SQL query to find the second and nth highest salary in an employee table?
Treat equal salaries as one rank and exclude employees whose salary is NULL. The provided solution returns the second-highest distinct salary; the same query can be adjusted for any fixed rank.
salary| Column | Type | Description |
|---|---|---|
| employee_idPK | INT | Unique employee identifier |
| employee_name | VARCHAR(100) | Employee full name |
| department | VARCHAR(50) | Employee department |
| salary | NUMERIC(12,2) | Annual employee salary |
| hire_date | DATE | Employee hire date |