0
← Exercises/
Window Functions•9 of 14
Window FunctionsAdvancedPRO

Department Salary Percentile with PERCENT_RANK()

Scenario

Compensation committees evaluate how an individual employee's salary compares relative to peers in the exact same department on a normalized 0.0 to 1.0 percentile scale.

Task
For each employee in `corp_payroll`, calculate their department salary percentile using `PERCENT_RANK()`. Return: 1. `emp_id` 2. `full_name` 3. `department` 4. `salary` 5. `salary_percentile`: `ROUND(PERCENT_RANK() OVER (PARTITION BY department ORDER BY salary ASC)::numeric, 2)` Order results by `department` ascending, then by `salary` ascending, then by `emp_id` ascending.
Expected Output Format

Employee salary percentile within department on a 0.00 to 1.00 scale.

Input Tables & Sample Data0 tables
Loading database schema...
Need a hint?
query.sql|Local Sandbox
Loading SQL editor...
Click "Run" or press ⌘ + Enter to execute your query

About the “Department Salary Percentile with PERCENT_RANK()” SQL Problem

Business Scenario

Compensation committees evaluate how an individual employee's salary compares relative to peers in the exact same department on a normalized 0.0 to 1.0 percentile scale.

Expected Output & Criteria

Employee salary percentile within department on a 0.00 to 1.00 scale.

Database Table Schema (PostgreSQL DDL)

PostgreSQL 16 WASM

This challenge executes directly against the following relational schema in your browser:

CREATE TABLE corp_payroll (
        emp_id INT PRIMARY KEY,
        full_name VARCHAR(100) NOT NULL,
        department VARCHAR(50) NOT NULL,
        salary NUMERIC(10, 2) NOT NULL
      );

Target SQL Clauses & Operators

PERCENT_RANKOVERPARTITION BYROUND

Want more Window Functions practice?

Explore the full syllabus of 14 exercises, syntax guides, and interview pitfalls.

View Window Functions Track→