A comprehensive analytics system for customer segmentation, journey tracking, and market basket analysis built on SQL.
This repository contains a set of SQL scripts and database schemas designed to analyze customer behavior, track marketing effectiveness, and provide actionable insights for retail and e-commerce businesses. The system combines RFM (Recency, Frequency, Monetary) analysis with journey performance tracking and market basket analysis.
The core database structure includes tables for:
Customer: Customer demographics and personal informationUser: User accounts linked to customersStore: Retail location informationProduct: Product catalog with categorizationTransaction: Purchase records linking customers, products, and storesJourney: Marketing campaign definitions and parametersPromotion_Code: Tracking of promotion code usageDelivery: Records of marketing materials delivered to customers
The system implements a robust RFM (Recency, Frequency, Monetary) analysis framework:
- Recency: How recently a customer made a purchase
- Frequency: How often a customer makes purchases
- Monetary: How much a customer spends
Customers are assigned scores (1-5) in each category and grouped into 11 personas:
- Champions
- Loyal Customers
- Potential Loyalists
- New Customers
- Promising
- Cannot Lose Them
- Needs Attention
- Hibernating Customers
- At Risk
- About To Sleep
- Lost Customers
The system tracks how customers move between different RFM segments over time, allowing businesses to:
- Identify which segments are growing or shrinking
- Monitor changes in spending patterns
- Measure the effectiveness of retention strategies
Track the effectiveness of marketing campaigns by:
- Measuring conversion rates from journey delivery to purchase
- Analyzing promotion code usage
- Comparing revenue from different customer segments
- Breaking down performance by store location
Identify product associations to support cross-selling strategies by:
- Analyzing purchase patterns within 90-day windows
- Calculating product pairing frequencies
- Identifying which products are commonly bought together
- Quantifying the strength of product relationships
CustomerSegmentByRFM.sql: Calculates RFM scores and assigns customer personasRFMByMonth.SQL: Tracks monthly RFM metrics for customersCustomerRFMMovement.sql: Analyzes movement between RFM segments over timeJourneyPerformance.sql: Measures marketing journey effectivenessMarketBasket.sql: Identifies product purchase associations
- Execute the database schema creation scripts to set up your tables
- Run the analytics scripts in the following order:
- CustomerSegmentByRFM.sql
- RFMByMonth.SQL
- CustomerRFMMovement.sql
- Other analysis scripts as needed
- Customer Segmentation: Identify your most valuable customers and those at risk
- Targeted Marketing: Deliver personalized campaigns based on RFM personas
- Retention Strategies: Monitor movement between segments to measure effectiveness
- Cross-Selling: Use market basket insights to make relevant product recommendations
- Campaign Optimization: Measure journey performance to refine marketing strategies
- SQL database (compatible with standard SQL syntax)
- Sufficient transaction history (at least 12 months recommended)
- Regular execution schedule for trend analysis
Contributions to improve the analytics scripts or extend functionality are welcome. Please submit pull requests or open issues to discuss potential improvements.