Write a SQL query to find the second-highest-paid employee within each department.
Use the provided employees and departments tables. Treat the second-highest salary as the second distinct salary, and return every employee tied at that salary.
department_id, department_name, employee_id, employee_name, and salarydepartment_id, then employee_id| Column | Type | Description |
|---|---|---|
| department_idPK | INT | Unique department identifier |
| department_name | VARCHAR(100) | Department name |
| Column | Type | Description |
|---|---|---|
| employee_idPK | INT | Unique employee identifier |
| employee_name | VARCHAR(100) | Employee full name |
| department_id | INT | Employee department reference |
| salary | NUMERIC(12,2) | Annual employee salary |