Sign in
Problems/292. Median Salary by Department using PERCENTILE_CONT
PrevNext

Median Salary by Department using PERCENTILE_CONT

hard
PERCENTILE_CONT
ordered-set aggregate
window functions
GROUP BY
statistics
Google
Meta
LinkedIn

Queries run in DuckDB in your browser. Syntax is close to Postgres; some MySQL/SQL Server functions will not work here.

An employee_salaries table stores salaries by department. For each department, compute the median salary using PERCENTILE_CONT(0.5), the mean salary (rounded to nearest integer), and the min/max salary range.

Table: employee_salaries

ColumnType
departmentVARCHAR
employee_idINT
salaryINT

Output columns: department, median_salary, avg_salary (rounded), min_salary, max_salary, employee_count. Order by department.

Schema

employee_salaries

department VARCHARemployee_id INTsalary INT

departmentemployee_idsalary
Engineering195000
Engineering2105000
Engineering3115000
Engineering488000
Engineering5132000
Engineering678000
Sales765000
Sales872000
Sales968000
Sales1085000
Sales1175000
HR1260000
HR1355000
HR1463000
HR1558000
SQL editor · DuckDB
Results

Write a query and press Run. DuckDB executes it in your browser.