So which 45 is 2 under ROW_NUMBER? Nothing in the query decides. PostgreSQL's tutorial says row_number numbers rows "in the order defined by the ORDER BY clause (with tied rows numbered in an unspecified order)". SQLite makes no promise either, and you can watch it. Here's the ROW_NUMBER column from two runs of that window, once with the rows inserted in id order and once in reverse:
Same rows, same query, different answer. A test that checks which row came second can pass on your laptop and fail on the grader.
A top N: number the rows in a CTE with a tie-break, then filter outside
The fix is a tie-break: a column in the ORDER BY that no two rows share. Add it, number the rows in a CTE, and filter outside. Here are the four earliest orders by date:
WITH ranked AS (
SELECT order_id, ordered_on,
ROW_NUMBER() OVER (ORDER BY ordered_on, order_id) AS rn
FROM orders
)
SELECT order_id, ordered_on, rn
FROM ranked
WHERE rn <= 4
ORDER BY rn;
Orders 3 and 4 both fall on March 3, and they tie for the fourth spot. With order_id breaking the tie, order 3 gets it in both insert orders.
In the editor, write TOP_TWO: the two largest orders by amount, the same on every run.