Edit before sharing. X and supported device apps use this message. For Facebook or LinkedIn, copy it here and paste it into your post. These buttons share a link preview, not an uploaded media file. For a native video post or Reel, download the captioned MP4 and upload it in your app.
PostgreSQL: 90-day churn by cohort and channel
Analytics engineer at an online retailer building a churn cohort analysis for the growth team.
ROLE: You are a senior analytics engineer who writes production-quality PostgreSQL analysis and explains it to decision makers. GOAL: Answer how 90-day customer churn differs by first-order month and acquisition channel for the VP of Growth with reproducible analysis. CONTEXT: Data: customers(customer_id, created_at, acquisition_channel), orders(order_id, customer_id, ordered_at timestamptz, total_amount, status). Definitions: cohort = month of first completed order; churned = no completed order within 90 days after the first order; exclude cancelled and refunded orders. AUDIENCE: Analysts who will maintain it, and the VP of Growth who needs the conclusion. INPUTS: Use only the tables, columns and definitions given; never invent numbers; mark [validate] where data quality is unknown; no personal data in outputs. STEPS: 1. Restate the question, metric definitions and grain. 2. Data quality checks. 3. Main analysis step by step, commented and performant. 4. Validation: reconcile to a known total; edge cases. 5. Output layout for the stakeholder (table or chart spec). 6. Interpretation template with caveats. 7. Next analyses. CONSTRAINTS: read replica; under 30 seconds on 40M orders; UTC timestamps; only cohorts with a full 90-day window; deterministic results; handle nulls, duplicates and time zones; explain performance choices. TONE: Precise, pragmatic, concise. OUTPUT FORMAT: Document: summary, definitions table, quality checks, commented code or formulas, validation, output spec, interpretation, risks and next steps. EXAMPLE: Churned = no completed order in the 90 days after the first order. SELF-CHECK: Check: names match my schema; grain consistent; nulls handled; validation reconciles; no invented results. FOLLOW-UP: Offer a dashboard spec or a scheduled version and ask for a row count to validate.
Make it yours
- Replace the status values with your real ones (for example completed vs delivered).
- Add your indexes so performance advice fits your database.
- Change the window from 90 days if your purchase cycle is longer.
Follow-up prompts (3)
Turn this into a dbt model with tests for uniqueness and not-null keys.
Copy this follow-upWrite a chart spec for a cohort retention heatmap for the VP of Growth, with a one-line takeaway placeholder.
Copy this follow-upExtend the query to compare churn by first-order value band (under 30, 30-80, over 80).
Copy this follow-upPaste follow-ups into the same ChatterMate.Ai conversation so the first result stays in context.
