Your question is Rank Rows With SQL Window Functions. Start with the requirements and the two tables 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.
Tech Mahindra's workforce analytics team needs to compare active employees within their departments. Write a PostgreSQL query that ranks employees by salary within each department.
employment_status = 'Active'.RANK() to rank salaries from highest to lowest independently within each department. Treat missing salaries as the lowest values.| 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 | Employee's department identifier |
| employee_name | VARCHAR(100) | Employee's full name |
| salary | INT | Annual salary |
| employment_status | VARCHAR(20) | Current employment status |