Untitled
unknown
plain_text
2 years ago
580 B
9
Indexable
WITH profiles as (SELECT
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
GROUP BY
user_id, DATE_TRUNC('month', created_at))
SELECT EXTRACT(month FROM AGE(DATE_TRUNC('month', o.paid_at)::date, profiles.start_cohort)) AS lifetime,
o.paid_at::date AS order_date,
start_cohort,
cohort_size,
total_amt
FROM profiles
JOIN tools_shop.orders o ON profiles.user_id = o.user_id;
Editor is loading...