Skip to content

debugwithnitin/SQL-MINI-PROJECT

Repository files navigation

📊 Intermediate SQL - Sales Analysis

🚀 Project Overview

This project performs in-depth customer and sales analysis for an e-commerce business using SQL (PostgreSQL).
The goal: improve customer retention and maximize revenue by analyzing segmentation, cohorts, and retention patterns.


🎯 Key Focus Areas

  • 🧑‍🤝‍🧑 Customer Segmentation – Identify high, mid, and low-value customers
  • 📆 Cohort Analysis – Measure revenue patterns across acquisition years
  • 🔄 Retention Analysis – Understand churn trends and re-engagement opportunities

📊 Business Questions Addressed

🧑‍🤝‍🧑 Customer Segmentation

  • Who are our most valuable customers?
  • How much revenue do they contribute?

📆 Cohort Analysis

  • How do different customer cohorts generate revenue over time?
  • Are newer cohorts spending as much as older ones?

🔄 Retention Analysis

  • Which customers haven’t purchased recently?
  • What does long-term retention look like?

🛠️ Technical Implementation

  • Database: PostgreSQL
  • Tools: DBeaver, ChatGPT for visualization
  • SQL Features Used:
    • ✅ Common Table Expressions (CTEs) & Subqueries
    • ✅ Window Functions (ROW_NUMBER, LAG, LEAD)
    • ✅ Aggregations (SUM, COUNT, AVG)
    • ✅ Conditional Logic (CASE, COALESCE)
    • ✅ Views for Data Cleaning & Transformation

📈 Key Analysis & Visualizations

1️⃣ Customer Segmentation

Query : 1_customer_segmentation

  • High-value segment (25%) → 66% of revenue ($135.4M)
  • Mid-value segment (50%) → 32% of revenue ($66.6M)
  • Low-value segment (25%) → 2% of revenue ($4.3M)

1_customer_segmentation

💡 Business Insight:

  • Launch VIP program for 12,372 top customers
  • Create upgrade paths for mid-value customers to unlock $66M → $135M potential
  • Run re-engagement campaigns for low-value, price-sensitive users

2️⃣ Cohort Analysis

Query : 2_cohort_analysis

  • Revenue & customers peaked in 2022–2023 but declined in 2024
  • Average customer revenue dropped from ~$2,800 (2016–2018) → ~$1,970 (2024)

2_cohort_analysis

💡 Business Insight:

  • Stabilize revenue with loyalty or subscription programs
  • Apply successful 2016–2018 strategies to new cohorts
  • Personalized re-engagement campaigns for 2022–2024 cohorts

3️⃣ Customer Retention

Query : 3_retention_analysis

  • Churn stabilizes around 90% after 2-3 years
  • Retention consistently <10% across cohorts

3_retention_analysis

💡 Business Insight:

  • Improve first 1–2 year onboarding with incentives & rewards
  • Focus on high-value win-back campaigns
  • Build churn prediction models to intervene early

Technical Details

  • Database: PostgreSQL
  • Analysis Tools: PostgreSQL, Dbeaver
  • Visualization: ChatGPT

📚 Learnings & Takeaways

✅ Deepened understanding of window functions, cohort analysis, and retention modeling.

✅ Practiced writing clean, modular SQL queries using CTEs and views.

✅ Learned how to turn raw data into actionable business recommendations.

🚀 Next Steps

🔮 Extend with:

Automated retention dashboards (using Power BI or Tableau). Machine learning churn prediction model. Email campaign recommendations for each segment.

🙌 Acknowledgments

Special thanks to Luke Barousse for inspiring this project and providing a clear framework for SQL-based sales analytics.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published