Esto se puede hacer usando una función de ventana:
SELECT order_id,
user_id,
orderdat,
row_number() over (partition by user_id order by orderedat ) as orders_so_far
FROM orders
order by user_id, orderdat
Esto se puede hacer usando una función de ventana:
SELECT order_id,
user_id,
orderdat,
row_number() over (partition by user_id order by orderedat ) as orders_so_far
FROM orders
order by user_id, orderdat