user_id
, created_at
, and the date of the next purchase using the LEAD window function.user_id
and order by created_at
to ensure the next purchase is for the same user and follows the current purchase chronologically.user_id
s that meet the active user criteria.erDiagram Users { int user_id varchar item datetime created_at int amount }