Turning Learners Into Developers
Codekilla
CODEKILLA
Hard
SQL-W10sql

Median Salary Per Department

Problem

From `employees(dept_id, salary)`, compute the **median** salary per dept. Output (dept_id, median_salary). Even-count depts: average the two middle values.

Input
employees
Output
dept_id, median_salary
Constraints
1 ≤ rows ≤ 10^6
Sample input
see prompt
Sample output
...
Explanation
Use ROW_NUMBER from both ends and average the middle one or two rows.
window-fnmedianpercentile@Bloomberg
Visible test cases
in: see
out: ...
Your solution — run it, use AI if stuck
sql