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.
Expected output sample
| user_id | product | amount | ts | purchase_no |
|---|---|---|---|---|
| 10 | Keyboard | 50.00 | 2024-01-01 10:00:00 | 1 |
| 10 | Mouse | 25.00 | 2024-01-01 10:10:00 | 2 |
| 10 | Monitor | 300.00 | 2024-01-01 10:20:00 | 3 |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign inFocus radio
Paused · SomaFM · Fluid