mirror of
https://github.com/freedbygrace/SQL.git
synced 2026-07-26 11:28:16 +00:00
aa803bd3bd
Major expansion from fraud detection to comprehensive business analytics: DATABASE CHANGES: - Renamed database from 'fraud_detection' to 'business_analytics' - Renamed user from 'fraud_analyst' to 'data_analyst' - Expanded from 20 to 39 tables across 4 business models NEW MODELS (19 tables): 1. Customer Analytics (5 tables): - customer_segments, customer_lifetime_value, churn_predictions - customer_satisfaction, engagement_metrics 2. Sales & Revenue Analytics (6 tables): - product_catalog, sales_transactions, sales_targets - sales_performance, revenue_forecasts 3. KPI & Metrics (8 tables): - kpi_definitions, daily_metrics, monthly_summaries - trend_analysis, dashboard_snapshots - report_definitions, report_executions, data_quality_checks DATA GENERATION: - Extended generate_data.sh with 6 new steps (now 15 total) - Added CLV calculations for all customers - Added churn predictions based on transaction recency - Added 30K customer satisfaction surveys - Added 1M sales transactions linked to 24 products - Added 90 days of daily KPI metrics - Added 24 months of business summaries SQL EXERCISES (3 new levels): - Level 2: Customer Analytics (10 exercises + 3 challenges) - Level 3: Sales & Revenue Analysis (12 exercises + 3 challenges) - Level 4: KPI Dashboards & Metrics (12 exercises + 3 challenges) DOCUMENTATION: - Updated README.md with business analytics focus - Updated QUICKSTART.md with new data generation steps - Updated SETUP_COMPLETE.md with 39-table architecture - Added DATA_MODELS.md with complete model specifications - Added WHATS_NEW.md with migration guide SEED DATA: - Added 8 customer segments (VIP, High Value, etc.) - Added 24 products across 5 categories - Added 16 KPI definitions across 4 categories - Added 8 standard report definitions All changes maintain idempotency and backward compatibility with existing fraud detection functionality.
267 lines
6.8 KiB
Markdown
267 lines
6.8 KiB
Markdown
# What's New - Business Analytics Database
|
|
|
|
## 🎯 Major Update: Aligned with Data Analyst Role
|
|
|
|
The database has been **expanded and refocused** to align with real-world **Data Analyst** responsibilities:
|
|
|
|
- ✅ Routine and semi-routine analysis
|
|
- ✅ Dashboard creation and maintenance
|
|
- ✅ Business trend identification
|
|
- ✅ Statistical analysis and pattern recognition
|
|
- ✅ Stakeholder reporting
|
|
|
|
---
|
|
|
|
## 📊 Database Renamed
|
|
|
|
**Old Name:** `fraud_detection`
|
|
**New Name:** `business_analytics`
|
|
|
|
**User Changed:** `fraud_analyst` → `data_analyst`
|
|
|
|
This better reflects the broader scope of business intelligence and analytics work.
|
|
|
|
---
|
|
|
|
## 🆕 New Data Models Added
|
|
|
|
### 1. Customer Analytics Model (5 Tables)
|
|
**Purpose:** Routine customer analysis and segmentation
|
|
|
|
#### New Tables:
|
|
- **`customer_segments`** - Customer classification definitions
|
|
- **`customer_lifetime_value`** - CLV calculations and tracking
|
|
- **`churn_predictions`** - Customer retention risk analysis
|
|
- **`customer_satisfaction`** - NPS, CSAT scores, and feedback
|
|
- **`engagement_metrics`** - Customer interaction tracking
|
|
|
|
**Use Cases:**
|
|
- Customer segmentation analysis
|
|
- Churn risk identification
|
|
- Lifetime value calculations
|
|
- Satisfaction trend analysis
|
|
- Engagement scoring
|
|
|
|
---
|
|
|
|
### 2. Sales & Revenue Analytics Model (6 Tables)
|
|
**Purpose:** Semi-routine sales reporting and forecasting
|
|
|
|
#### New Tables:
|
|
- **`product_catalog`** - Product master data
|
|
- **`sales_transactions`** - Detailed sales records
|
|
- **`sales_targets`** - Performance goals and targets
|
|
- **`sales_performance`** - Aggregated performance metrics
|
|
- **`revenue_forecasts`** - Revenue predictions and variance
|
|
|
|
**Use Cases:**
|
|
- Sales performance dashboards
|
|
- Product analysis
|
|
- Revenue forecasting
|
|
- Target vs. actual analysis
|
|
- Channel performance comparison
|
|
|
|
---
|
|
|
|
### 3. Operational Metrics & KPI Model (5 Tables)
|
|
**Purpose:** Dashboard creation and KPI tracking
|
|
|
|
#### New Tables:
|
|
- **`kpi_definitions`** - Master KPI catalog
|
|
- **`daily_metrics`** - Daily operational snapshots
|
|
- **`monthly_summaries`** - Monthly business summaries
|
|
- **`trend_analysis`** - Statistical trend tracking
|
|
- **`dashboard_snapshots`** - Pre-calculated dashboard data
|
|
|
|
**Use Cases:**
|
|
- Executive dashboards
|
|
- KPI monitoring
|
|
- Trend analysis
|
|
- Performance tracking
|
|
- Anomaly detection
|
|
|
|
---
|
|
|
|
### 4. Business Intelligence & Reporting Model (3 Tables)
|
|
**Purpose:** Report management and data quality
|
|
|
|
#### New Tables:
|
|
- **`report_definitions`** - Standard report catalog
|
|
- **`report_executions`** - Report run history
|
|
- **`data_quality_checks`** - Data validation tracking
|
|
|
|
**Use Cases:**
|
|
- Report scheduling
|
|
- Execution monitoring
|
|
- Data quality assurance
|
|
- Audit trails
|
|
|
|
---
|
|
|
|
## 📈 Total Database Size
|
|
|
|
### Original (Fraud Detection Only):
|
|
- **20 tables** focused on fraud investigation
|
|
|
|
### Updated (Business Analytics):
|
|
- **39 tables** covering:
|
|
- Fraud detection (original 20 tables)
|
|
- Customer analytics (5 tables)
|
|
- Sales & revenue (6 tables)
|
|
- KPIs & metrics (5 tables)
|
|
- Reporting & BI (3 tables)
|
|
|
|
---
|
|
|
|
## 🔗 Integration with Existing Data
|
|
|
|
The new models **integrate seamlessly** with existing tables:
|
|
|
|
```
|
|
customers → customer_lifetime_value
|
|
→ churn_predictions
|
|
→ customer_satisfaction
|
|
→ engagement_metrics
|
|
|
|
transactions → sales_transactions
|
|
→ sales_performance
|
|
→ revenue_forecasts
|
|
|
|
(all tables) → kpi_definitions
|
|
→ daily_metrics
|
|
→ monthly_summaries
|
|
```
|
|
|
|
---
|
|
|
|
## 💼 Data Analyst Workflows Supported
|
|
|
|
### Daily Routine Tasks
|
|
1. **Refresh dashboards** using `dashboard_snapshots`
|
|
2. **Update daily metrics** in `daily_metrics`
|
|
3. **Run data quality checks** via `data_quality_checks`
|
|
4. **Generate standard reports** from `report_definitions`
|
|
|
|
### Weekly Semi-Routine Tasks
|
|
1. **Customer segmentation** analysis using `customer_segments` and `customer_lifetime_value`
|
|
2. **Sales performance** review via `sales_performance` vs `sales_targets`
|
|
3. **Churn prediction** updates in `churn_predictions`
|
|
4. **Trend analysis** using `trend_analysis` table
|
|
|
|
### Monthly Analysis
|
|
1. **Monthly summaries** generation in `monthly_summaries`
|
|
2. **Revenue forecasting** via `revenue_forecasts`
|
|
3. **Customer satisfaction** trend analysis
|
|
4. **KPI performance** review
|
|
|
|
### Ad-Hoc Analysis
|
|
1. **Product performance** deep-dives
|
|
2. **Customer cohort** analysis
|
|
3. **Seasonal pattern** identification
|
|
4. **Anomaly investigation**
|
|
|
|
---
|
|
|
|
## 🎓 New Learning Opportunities
|
|
|
|
### For Beginners:
|
|
- Basic aggregations (SUM, AVG, COUNT)
|
|
- Simple JOINs across analytics tables
|
|
- Date-based filtering and grouping
|
|
- KPI calculations
|
|
|
|
### For Intermediate:
|
|
- Customer segmentation queries
|
|
- Sales trend analysis
|
|
- Moving averages and window functions
|
|
- Cohort analysis
|
|
|
|
### For Advanced:
|
|
- Churn prediction analysis
|
|
- Revenue forecasting validation
|
|
- Multi-dimensional analysis
|
|
- Statistical significance testing
|
|
|
|
---
|
|
|
|
## 🔄 Migration Notes
|
|
|
|
### What Changed:
|
|
- ✅ Database name: `fraud_detection` → `business_analytics`
|
|
- ✅ User name: `fraud_analyst` → `data_analyst`
|
|
- ✅ Container names updated
|
|
- ✅ All scripts updated
|
|
- ✅ 19 new tables added
|
|
|
|
### What Stayed the Same:
|
|
- ✅ All original 20 fraud detection tables
|
|
- ✅ All existing data generation logic
|
|
- ✅ All existing indexes and constraints
|
|
- ✅ Idempotent script design
|
|
- ✅ Docker setup structure
|
|
|
|
### Backward Compatibility:
|
|
- ✅ All original fraud detection exercises still work
|
|
- ✅ All original queries still valid
|
|
- ✅ No breaking changes to existing schema
|
|
|
|
---
|
|
|
|
## 📝 Next Steps
|
|
|
|
### Immediate:
|
|
1. ✅ Schema updated with 19 new tables
|
|
2. ⏳ Update data generation scripts
|
|
3. ⏳ Create SQL exercises for new models
|
|
4. ⏳ Update main documentation
|
|
|
|
### Future Enhancements:
|
|
- Add sample data for new tables
|
|
- Create dashboard query examples
|
|
- Build KPI calculation examples
|
|
- Add data quality check templates
|
|
|
|
---
|
|
|
|
## 🚀 Getting Started with New Models
|
|
|
|
### Quick Test Queries:
|
|
|
|
```sql
|
|
-- Check new tables exist
|
|
SELECT table_name
|
|
FROM information_schema.tables
|
|
WHERE table_schema = 'public'
|
|
AND table_name IN (
|
|
'customer_segments',
|
|
'customer_lifetime_value',
|
|
'product_catalog',
|
|
'sales_transactions',
|
|
'kpi_definitions',
|
|
'daily_metrics'
|
|
);
|
|
|
|
-- View table counts
|
|
SELECT
|
|
'customer_segments' as table_name, COUNT(*) FROM customer_segments
|
|
UNION ALL
|
|
SELECT 'product_catalog', COUNT(*) FROM product_catalog
|
|
UNION ALL
|
|
SELECT 'kpi_definitions', COUNT(*) FROM kpi_definitions;
|
|
```
|
|
|
|
---
|
|
|
|
## 📚 Documentation Updates
|
|
|
|
- ✅ **DATA_MODELS.md** - Complete model documentation
|
|
- ✅ **WHATS_NEW.md** - This file
|
|
- ⏳ **README.md** - Update with new scope
|
|
- ⏳ **QUICKSTART.md** - Add new model examples
|
|
- ⏳ **Exercises** - Create analytics-focused exercises
|
|
|
|
---
|
|
|
|
**The database is now a comprehensive Business Analytics platform suitable for Data Analyst training and real-world analysis scenarios!** 🎉
|
|
|