Homeโ€บQuery Libraryโ€บDatabase

What is your churn rate โ€” and is it getting better or worse?

Churn rate by cohort is the most honest measure of retention health in a subscription business. This query tracks the percentage of customers who become inactive within each signup cohort.

๐Ÿ“Š Any SQL database๐Ÿ‘ฅ SaaS and subscription businesses๐Ÿ”ค Plain-English โ†’ SQL

This is part of the Taptic Data Database query library. Explore related queries: SQL query for monthly revenue trend, SQL query for top customers by revenue, SQL query for revenue by region, and more.

Show me customer churn rate by signup month cohort for the last 12 months
โ†“
Customer Churn Rate by Cohort โ€” generated by Taptic Data AI
WITH cohorts AS (
  SELECT
    customer_id,
    DATE_TRUNC('month', signup_date)::date AS cohort_month
  FROM customers
),
activity AS (
  SELECT
    customer_id,
    MAX(order_date)::date              AS last_active
  FROM orders
  WHERE status NOT IN ('cancelled', 'refunded')
  GROUP BY customer_id
)
SELECT
  TO_CHAR(c.cohort_month, 'YYYY-MM')  AS cohort,
  COUNT(*)                             AS cohort_size,
  COUNT(*) FILTER (
    WHERE a.last_active < CURRENT_DATE - INTERVAL '90 days'
      OR a.last_active IS NULL
  )                                    AS churned,
  COUNT(*) FILTER (
    WHERE a.last_active >= CURRENT_DATE - INTERVAL '90 days'
  )                                    AS still_active,
  ROUND(
    COUNT(*) FILTER (
      WHERE a.last_active < CURRENT_DATE - INTERVAL '90 days'
        OR a.last_active IS NULL
    ) * 100.0 / NULLIF(COUNT(*), 0), 1
  )                                    AS churn_rate_pct
FROM cohorts c
LEFT JOIN activity a USING (customer_id)
WHERE c.cohort_month >= NOW() - INTERVAL '12 months'
  AND c.cohort_month < DATE_TRUNC('month', CURRENT_DATE) - INTERVAL '3 months'
GROUP BY c.cohort_month
ORDER BY c.cohort_month ASC
Schema-aware SQL generated from plain English36 lines

This query was generated by Taptic Data from plain English against a real Any SQL database schema. In Taptic, you type the question โ€” the AI writes the SQL, runs it, and returns the result. You can edit the SQL, ask for explanations, and save it as a refreshable report.

Breaking it down line by line

  1. CTE "cohorts" assigns each customer to their signup month
  2. CTE "activity" finds the most recent order date per customer as a proxy for activity
  3. A customer is considered churned if their last activity is more than 90 days ago or they never ordered
  4. The WHERE clause excludes cohorts from the last 3 months โ€” too early to measure churn meaningfully
  5. PostgreSQL FILTER clause enables counting churned and active in the same query without CASE

Result description

Monthly cohort table with cohort size, churned count, still-active count, and churn rate percentage โ€” covering cohorts old enough to have meaningful churn data.

The business impact

Overall churn rate masks cohort-level trends. If your January cohort churned at 40% but your April cohort is at 20%, your product improvements are working. If it is the other way around, something recent is driving customers away. Cohort-level churn is the only way to see this.

Common questions

How do I generate a "Customer Churn Rate by Cohort" query automatically?
In Taptic Data, type "Show me customer churn rate by signup month cohort for the last 12 months" and the AI generates schema-aware SQL against your real Any SQL database data โ€” no manual writing required.
What database does this query work with?
This query is designed for Any SQL database. Taptic reads your live schema so the generated SQL always matches your actual table and column names.
Can I edit the generated SQL?
Yes. Taptic shows you the exact SQL it generated. You can edit it directly, ask the AI to explain any line, or request a revision in plain English.
Can I save this as a scheduled report?
Yes. Once you run this query in Taptic, you can save it as a report, add charts and KPIs, and schedule it to email your team on any cadence โ€” daily, weekly, or monthly.

Skip the SQL. Ask the question.

In Taptic Data, you type "Show me customer churn rate by signup month cohort for the l..." and this SQL runs automatically against your real Any SQL database data.

Try Taptic Free โ€” $29.99/mo

No credit card required. Connect your data source in under 5 minutes.