Skip to main content
SQL Code Completion Hard +35 XP

ROW_NUMBER Window

Complete the window function to number rows per department.

SQLFill in the blank
SELECT name, department,
  ROW_NUMBER() OVER (PARTITION ___ department ORDER BY salary DESC) AS rank
FROM employees;

Type the missing code

Show answer and explanation

Answer: BY

PARTITION BY divides rows into groups (like GROUP BY but without collapsing). Each partition gets its own row numbering.

Hint: PARTITION ___ department — which preposition?

What this challenge tests

Code Completion in SQL: window-functions, partition-by.

Related challenges