Data Analysis & SQL5.0 · 0 ratings

RFM Customer Segmentation

Scores customers by Recency, Frequency, and Monetary value into actionable segments with SQL.

Role-BasedStep-by-StepStructured-Output

Prompt

ROLE: You are a CRM analyst building an RFM segmentation for marketing.

CONTEXT: Build RFM segments from transactions in [TRANSACTIONS_TABLE] (columns: customer_id, order_timestamp, order_value). Analysis as-of date: [AS_OF_DATE]. Engine: [DATABASE_ENGINE]. Desired number of score buckets: [N_BUCKETS] (typically 5).

TASK:
1. Define Recency, Frequency, and Monetary precisely (recency = days since last order as of [AS_OF_DATE]; frequency = order count in window; monetary = total or average value -- state which).
2. Use NTILE([N_BUCKETS]) to score each dimension 1-5 (handle recency so that more recent = higher score).
3. Combine into an RFM code and map code ranges to named segments (Champions, Loyal, At Risk, Hibernating, Lost, New) with the mapping rules stated.
4. Output per-segment customer counts and revenue share.
5. Recommend one marketing action per segment.

OUTPUT FORMAT: Definitions -> Scoring ```sql``` -> Segment mapping table -> Segment summary query -> Recommended actions.

CONSTRAINTS: Make recency scoring direction explicit (low days = high score). Handle ties and customers with a single order. Exclude refunds/test accounts if present. Keep [AS_OF_DATE] parameterized so the model is reproducible.

How to use this prompt

  1. 1

    Copy the prompt above and paste it into ChatGPT, Claude, or Gemini — or open it in the visual Studio to edit each part on a canvas and run it with your own key.

  2. 2

    Replace any bracketed placeholders with your specifics. The more concrete your context and constraints, the sharper the result — see the 5-part prompt structure.

  3. 3

    Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.

Techniques in this prompt

Role-Based

Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.

Learn this technique
Step-by-Step

Forces explicit intermediate reasoning instead of jumping to a conclusion, which improves accuracy on hard tasks.

Learn this technique
Structured Output

Pins the response to a defined structure so it drops straight into your workflow.

Learn this technique

Recommended models

claudegpt-4ogemini

Build on this prompt

Open it in the visual Studio to wire it into a full workflow with your own API key — or learn the craft behind prompts like this.

More in Data Analysis & SQL