Number rows within a partition — the most common "give me the Nth thing per group" pattern. Pair with a WHERE rn = 1 in an outer query to keep just the top row per group.
PostgreSQL `LATERAL` lets a join's right-hand side reference the left-hand row — like a correlated subquery, but supplying multiple columns or rows. Perfect for "top-N per group".