SELECT
customer,
order_date,
ROW_NUMBER() OVER (PARTITION BY customer ORDER BY order_date) AS order_sequence
FROM data
ORDER BY customer, order_sequence;
Run this query on the demo dataset →
ROW_NUMBER() assigns a strictly increasing integer (1, 2, 3, ...) within each partition, with no ties — here it numbers each customer’s orders in the order they were placed, which is useful for questions like "which was each customer’s first order".
A table named data with columns: order_id (integer), customer (text), country (text), category (text), quantity (integer), unit_price (real), order_date (text, YYYY-MM-DD).
Want to run it on your own file? Open it with Query CSV with SQL: your file becomes the table data, and you can paste this query with your own column names.