PERCENTILE_CONT for median.
For each department that has employees, return the median salary. Columns: `department_name`, `median_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.
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY salary) is the Postgres way.
Group by department and join to ci_departments for the name.
PERCENTILE_CONT interpolates between values for even-sized groups; PERCENTILE_DISC picks the nearest existing value.