WITH latest_customer_transactions AS (
SELECT
*, row_number() OVER (PARTITION BY user_id ORDER BY created_at desc) AS rownum
FROM
transactions
)
SELECT
id, customer_id
FROM
latest_customer_transactions
WHERE
rownum <= 10;