Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH user_profile AS (SELECT DISTINCT user_id,
- DATE_TRUNC ('month', created_at )::date AS start_cohort,
- COUNT (*) OVER (PARTITION BY DATE_TRUNC ('month', created_at )::date) AS cohort_size
- FROM tools_shop.users)
- SELECT EXTRACT(MONTH FROM AGE(DATE_TRUNC('day', o.created_at), up.start_cohort)) AS lifetime,
- DATE_TRUNC ('month', o.created_at )::date AS order_date,
- start_cohort,
- cohort_size,
- total_amt
- FROM user_profile up
- JOIN tools_shop.orders o ON up.user_id = o.user_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement