Customer Segmentation & Cohort Analysis
Use AI to build RFM analyses, behavioral segments, and cohort retention curves. Practical SQL queries and prompts for smarter customer segmentation.
Why Most Segmentation Is Too Simple
Most marketing teams segment by plan tier and maybe company size. That's table stakes. The analysts who drive real business impact segment by behavior — who's actually using the product, who's at risk, who looks like your best customers but hasn't upgraded yet. AI makes this level of segmentation accessible without a data science degree.
RFM Analysis: The Foundation
RFM (Recency, Frequency, Monetary) is the classic segmentation framework, and it's still incredibly useful. Recency = how recently they purchased or engaged. Frequency = how often they engage. Monetary = how much they spend. Score each dimension 1-5 and you get instant customer tiers.
WITH rfm_raw AS (
SELECT
customer_id,
DATEDIFF(day, MAX(order_date), CURRENT_DATE) AS recency_days,
COUNT(DISTINCT order_id) AS frequency,
SUM(order_value) AS monetary
FROM orders
WHERE order_date >= DATEADD(year, -1, CURRENT_DATE)
GROUP BY customer_id
),
rfm_scored AS (
SELECT
customer_id,
recency_days,
frequency,
monetary,
NTILE(5) OVER (ORDER BY recency_days ASC) AS r_score,
NTILE(5) OVER (ORDER BY frequency ASC) AS f_score,
NTILE(5) OVER (ORDER BY monetary ASC) AS m_score
FROM rfm_raw
)
SELECT
customer_id,
r_score,
f_score,
m_score,
CONCAT(r_score, f_score, m_score) AS rfm_segment,
CASE
WHEN r_score >= 4 AND f_score >= 4 AND m_score >= 4 THEN 'Champions'
WHEN r_score >= 4 AND f_score >= 3 THEN 'Loyal Customers'
WHEN r_score >= 4 AND f_score <= 2 THEN 'New Customers'
WHEN r_score <= 2 AND f_score >= 3 THEN 'At Risk'
WHEN r_score <= 2 AND f_score <= 2 AND m_score >= 3 THEN 'Can''t Lose Them'
WHEN r_score <= 2 AND f_score <= 2 AND m_score <= 2 THEN 'Hibernating'
ELSE 'Needs Attention'
END AS segment_label
FROM rfm_scored
ORDER BY monetary DESC;Turn RFM segments into a concrete marketing action plan
I have an RFM analysis with these segments and customer counts: Champions (450), Loyal (1,200), New Customers (800), At Risk (650), Can't Lose Them (180), Hibernating (2,100). Our average order value is $85 and customer acquisition cost is $45. For each segment, give me: (1) a specific marketing action to take this month, (2) the expected ROI of that action, (3) which channels to use, and (4) how to measure success. Prioritize the segments by potential revenue impact.
Behavioral Segmentation with AI
RFM is based on transaction data. Behavioral segmentation goes deeper — it looks at how people actually use your product or interact with your marketing. Which features do they use? What content do they consume? How do they navigate your site? AI is particularly good at finding behavioral patterns humans would miss.
Discover natural behavioral segments in your product usage data
I have product usage data for a SaaS platform with these event types: login, feature_A_used, feature_B_used, report_generated, invite_sent, settings_changed, support_ticket_opened, export_data. I want to identify natural behavioral segments. Help me: (1) Write SQL to create a user-level behavioral feature table, (2) Identify 4-6 meaningful behavioral segments, (3) Name each segment with a descriptive label, (4) Suggest marketing actions for each segment. Focus on segments that predict retention and expansion revenue.
Cohort Retention Curves
Cohort analysis tells you something no other analysis can: are things getting better or worse over time? By grouping customers by signup month and tracking their retention, you see whether product improvements and marketing changes are actually working.
WITH cohorts AS (
SELECT
customer_id,
DATE_TRUNC('month', first_order_date) AS cohort_month
FROM customers
),
activity AS (
SELECT
c.customer_id,
c.cohort_month,
DATE_TRUNC('month', o.order_date) AS activity_month,
DATEDIFF('month', c.cohort_month, DATE_TRUNC('month', o.order_date)) AS months_since_first
FROM cohorts c
JOIN orders o ON c.customer_id = o.customer_id
)
SELECT
cohort_month,
months_since_first,
COUNT(DISTINCT customer_id) AS active_customers,
ROUND(
COUNT(DISTINCT customer_id) * 100.0 /
FIRST_VALUE(COUNT(DISTINCT customer_id)) OVER (
PARTITION BY cohort_month ORDER BY months_since_first
), 1
) AS retention_pct
FROM activity
GROUP BY cohort_month, months_since_first
ORDER BY cohort_month, months_since_first;Manual Workflow
With AI
Combining Segmentation Approaches
The real power comes from combining RFM, behavioral, and cohort analyses. Your Champions segment from RFM should map to your Power Users in behavioral segmentation. If they don't, you've found a disconnect worth investigating. AI can help you cross-reference these models and find the overlaps and gaps.
Build an RFM analysis on your own customer data and ask AI to create an action plan
Here is my RFM segmentation data: [paste segment names, counts, and average revenue per segment]. Also, here are my cohort retention rates for the last 6 months: [paste retention data]. Help me: (1) Identify which RFM segments are growing vs. shrinking over time, (2) Find the highest-ROI segment to focus on this quarter, (3) Create a one-page executive summary I can present to leadership with specific recommendations and expected revenue impact.
Get weekly job alerts
Curated marketing analytics roles — delivered every Monday.