Meesho's People Analytics team wants a department-level view of salary equity and compensation ranges. Write a PostgreSQL query using CTEs and window functions to compare average salaries by gender and identify the second-highest distinct salary in each department.
Tie when the averages are equal and No gender data when no valid gender salary exists.NULL.department_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 |
| department_id | INT | Department assigned to the employee |
| gender_of_employee | VARCHAR(30) | Reported employee gender |
| salary | NUMERIC(12,2) | Annual employee salary |