SQL Practice Logo

SQLPractice Online

Scenario SQL Question

Salary vs Department Median & Percentile

Build mastery in Ctes Window with this scenario-based SQL challenge and live execution support.

Problem Statement

For each employee compute: their department's median salary, the difference from it, and their percentile rank within the department (PERCENT_RANK × 100, rounded to 2). Return department_name, first_name, last_name, salary, dept_median, diff_from_median, percentile_rank — ordered by department_name, salary DESC, employee_id.

Relevant Tables

employeesdepartments

SQL Concepts Used in This Scenario

Strengthen your understanding with these targeted learning topics: