ROW_NUMBER
Numbers rows 1, 2, 3… in a given order — across the whole result or within each group.
Syntax
ROW_NUMBER() OVER (ORDER BY <sort key>)
ROW_NUMBER() OVER (PARTITION BY <group> ORDER BY <sort key>)
A window function: it doesn't reduce the number of rows but adds a number to each one. PARTITION BY restarts the numbering in each group — that's how you build “top N in each category”.