Write logic to get the 3rd highest salary using SQL and PySpark, and if there are fewer than 3 values, take the second one.
Use the employee compensation records joined to employees. Treat salaries as distinct, ignore NULL salaries, and return the highest available salary if only one distinct value exists.
selected_salary.| Column | Type | Description |
|---|---|---|
| employee_idPK | INT | Unique employee identifier |
| employee_name | VARCHAR(100) | Employee full name |
| department | VARCHAR(80) | Employee department |
| Column | Type | Description |
|---|---|---|
| compensation_idPK | INT | Unique compensation record identifier |
| employee_id | INT | Referenced employee identifier |
| salary | NUMERIC(12,2) | Annual salary amount |