PostgreSQLWindow FunctionsROW_NUMBER
CORR

ROW_NUMBERWindow Functions

RANK

Assigns a unique sequential integer to each row within a partition.

Syntax

ROW_NUMBER() OVER (w)

Example

Enter values below to update the example in real time.

department_id
employee_id
salary
rank_in_dept
employees
SELECT department_id, employee_id, salary,
       ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rank_in_dept
FROM employees;