Creators to follow

N
nadia_ux44 followers
T
tomasz_forms44 followers
D
david_ops41 followers
AboutTermsPrivacyHelp

© 2026 teliprompt

RA
rachel_data
8 months ago•
Data & Analytics

Customer segmentation with RFM scoring in pure SQL

Claude Sonnet 4.6
code output
#sql
#rfm
#segmentation
#analytics
#postgres
Views
5.3K
Copies
1.8K
Likes
843
Comments
0
Copy rate
34.0%

Prompt

You are a senior analytics engineer. Write a production-ready RFM (Recency, Frequency, Monetary) analysis in [sql_dialect] for the table [orders_table]. Assume columns: customer_id, order_date, order_total, status.

Requirements:
1. Score each customer 1-5 on R, F, and M using NTILE
2. Compute a combined RFM score and segment label (Champions, Loyal, At Risk, etc.)
3. Include only completed orders from the last [lookback_days] days
4. Provide a segment summary with counts, average spend, and retention rate
5. Add clear comments explaining each CTE and the segmentation rules

Customise this prompt

Fill in 3 variables to personalise this prompt

Preview
You are a senior analytics engineer. Write a production-ready RFM (Recency, Frequency, Monetary) analysis in [sql_dialect] for the table [orders_table]. Assume columns: customer_id, order_date, order_total, status. Requirements: 1. Score each customer 1-5 on R, F, and M using NTILE 2. Compute a combined RFM score and segment label (Champions, Loyal, At Risk, etc.) 3. Include only completed orders from the last [lookback_days] days 4. Provide a segment summary with counts, average spend, and retention rate 5. Add clear comments explaining each CTE and the segmentation rules

Example output

Related prompts

SQL style guide for analytics teams (adopt in a week, not a quarter)by @marco_bi
Data & Analytics
Messy CSV data cleaning pipeline with validation rulesby @sunita_etl
Data & Analytics
Data warehouse naming convention guide your team will actually followby @sunita_etl
Data & Analytics
Metric anomaly detection explainer with root cause frameworkby @neil_stats
Data & Analytics