MSSQLWindow FunctionsROW_NUMBER
APPROX_COUNT_DISTINCT

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
rn
employees
SELECT department_id, employee_id, salary,
       ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rn
FROM employees;