Top-N per group with window functions.
Return the highest-paid employee in each department. Columns: `department_name`, `name`, `salary`. Order by department name. Tables: `ci_employees`, `ci_departments`.
| Column | Type | Key |
|---|---|---|
| id | INT | PK |
| name | TEXT | |
| department_id | INT | FK → ci_departments.id |
| manager_id | INT | FK → ci_employees.id |
| salary | INT | |
| hire_date | DATE |
| Column | Type | Key |
|---|---|---|
| id | INT | PK |
| name | TEXT |
Each hint you reveal reduces the XP you can earn. Try the query first.
ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC).
Wrap in a CTE and filter where rn = 1.