Assign row numbers within each partition.
Section: Querying, Joins, and Aggregation
Window function row_number
sql
sql
SELECT *, row_number() OVER (PARTITION BY customer_id ORDER BY created_at DESC)
FROM orders;Explanation
See summary for usage details.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Querying, Joins, and Aggregation