Purchase sequence number per user

Purchase sequence number per user

In table sales (id, user_id, product, amount, ts) number each purchase within every user_id in chronological order by ts, starting from 1. Return columns user_id, product, amount, ts, purchase_no. Order the result by user_id, then ts.

Row order matters

PostgreSQLv16

Your query result will appear here

Focus radio
Paused · SomaFM · Fluid