Live SQLite 3.54 Sandbox
SQL ROW_NUMBER() & PARTITION BY (with live sandbox)
ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...) assigns a unique 1, 2, 3 rank inside each group — the #1 SQL interview pattern for top-N-per-group.
Syntax
SELECT full_name, dept_id, salary, ROW_NUMBER() OVER (PARTITION BY dept_id ORDER BY salary DESC) AS rn FROM employees;Number employees within each dept_id by highest salary using ROW_NUMBER().
SQLite 3.50 SandboxCtrl/Cmd + Enter to Run (unlimited & ungraded)
Practise ROW_NUMBER() & PARTITION BY in our free SQL track
Same streak & XP across Excel, Google Sheets, and SQL.
Free 1-Page Excel, Google Sheets & SQL Interview Cheat Sheet
The 25 formulas, keyboard shortcuts, and SQL patterns tested most in analyst interviews — emailed instantly, zero spam.