Skip to content

Instantly share code, notes, and snippets.

@kxzk
Created March 21, 2024 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kxzk/b7a61a9aa6962cd4942c934c883c3740 to your computer and use it in GitHub Desktop.
Save kxzk/b7a61a9aa6962cd4942c934c883c3740 to your computer and use it in GitHub Desktop.
select distinct user_id
from events s3
inner join
(
select distinct user_id
from events s2
inner join
(
select distinct user_id
from events
where event = 'View Product'
and timestamp between '2017-09-01'::timestamp and now()
) s1
on s1.user_id = s2.user_id
and s2.timestamp < (s1.timestamp + '7 days'::interval)
-- and s2.timestamp > s1.timestamp
where s2.event = 'Add to Cart'
) s2
on s3.user_id = s2.user_id
and s3.timestamp < (s2.timestamp + '7 days'::interval)
-- and s3.timestamp > s2.timestamp
where s3.event = 'Checkout'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment