Dina_J

LTV

Nov 29th, 2024
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH user_profile AS
  2.     (SELECT users.user_id,
  3.            DATE_TRUNC('month', users.created_at)::date AS start_cohort,
  4.            COUNT(*) OVER (PARTITION BY DATE_TRUNC('month', users.created_at)) AS cohort_size
  5.            FROM tools_shop.users AS users)
  6.  
  7. SELECT
  8.     EXTRACT(MONTH FROM AGE(DATE_TRUNC('month', o.paid_at), up.start_cohort)) AS lifetime,
  9.     DATE_TRUNC('month', o.paid_at)::date AS order_month,
  10.     start_cohort,
  11.     cohort_size,
  12.     total_amt AS revenue
  13.  
  14. FROM user_profile AS up
  15. JOIN tools_shop.orders AS o ON up.user_id = o.user_id;
Advertisement
Add Comment
Please, Sign In to add comment