Problem Statement
Which window function assigns a unique sequence number to each row within its partition even when values tie?
Explanation
ROW_NUMBER always produces 1, 2, 3, and so on with no duplicates and no gaps, even when the ORDER BY values are the same.
RANK assigns the same rank to ties and leaves gaps. DENSE_RANK assigns the same rank to ties but does not leave gaps.
Code Solution
SolutionRead Only
SELECT order_id,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY created_at DESC, order_id DESC) AS rn
FROM orders;