├── Data-mining report.docx └── data-mining script.sql /Data-mining report.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rahat-karim/Data-mining-project/de60fc741e6a3bcca42d221762eada74b3c24816/Data-mining report.docx -------------------------------------------------------------------------------- /data-mining script.sql: -------------------------------------------------------------------------------- 1 | -- create schema retailshop; 2 | -- use retailshop; 3 | -- select * from online_retail; 4 | 5 | -- Define Metadata: 6 | DESCRIBE online_retail; 7 | 8 | -- Distribution of Order Values Across All Customers: 9 | SELECT CustomerID, SUM(UnitPrice * Quantity) AS OrderValue 10 | FROM online_retail 11 | GROUP BY CustomerID; 12 | 13 | -- Number of Unique Products Each Customer Purchased: 14 | SELECT CustomerID, COUNT(DISTINCT StockCode) AS UniqueProductsPurchased 15 | FROM online_retail 16 | GROUP BY CustomerID; 17 | 18 | -- Customers Who Have Made Only One Purchase: 19 | SELECT CustomerID 20 | FROM online_retail 21 | GROUP BY CustomerID 22 | HAVING COUNT(DISTINCT InvoiceNo) = 1; 23 | 24 | -- Most Commonly Purchased Products Together: 25 | SELECT a.StockCode AS Product1, b.StockCode AS Product2, COUNT(*) AS TimesPurchasedTogether 26 | FROM online_retail a 27 | JOIN online_retail b ON a.InvoiceNo = b.InvoiceNo AND a.StockCode < b.StockCode 28 | GROUP BY Product1, Product2 29 | ORDER BY TimesPurchasedTogether DESC 30 | LIMIT 10; 31 | 32 | -- Advanced Queries: 33 | -- Customer Segmentation by Purchase Frequency: 34 | SELECT CustomerID, 35 | COUNT(DISTINCT InvoiceNo) AS TotalPurchases, 36 | CASE 37 | WHEN COUNT(DISTINCT InvoiceNo) >= 20 THEN 'High Frequency' 38 | WHEN COUNT(DISTINCT InvoiceNo) BETWEEN 10 AND 19 THEN 'Medium Frequency' 39 | ELSE 'Low Frequency' 40 | END AS PurchaseFrequencySegment 41 | FROM online_retail 42 | GROUP BY CustomerID; 43 | 44 | -- Average Order Value by Country: 45 | SELECT Country, AVG(UnitPrice * Quantity) AS AvgOrderValue 46 | FROM online_retail 47 | GROUP BY Country; 48 | 49 | -- Customer Churn Analysis 50 | SELECT CustomerID 51 | FROM online_retail 52 | WHERE InvoiceDate < CURDATE() - INTERVAL 6 MONTH 53 | GROUP BY CustomerID; 54 | 55 | -- Product Affinity Analysis: 56 | SELECT a.StockCode AS Product1, b.StockCode AS Product2, COUNT(*) AS PurchaseTogether 57 | FROM online_retail a 58 | JOIN online_retail b ON a.InvoiceNo = b.InvoiceNo AND a.StockCode < b.StockCode 59 | GROUP BY Product1, Product2 60 | ORDER BY PurchaseTogether DESC; 61 | 62 | -- Time-Based Analysis 63 | SELECT YEAR(InvoiceDate) AS Year, MONTH(InvoiceDate) AS Month, SUM(UnitPrice * Quantity) AS TotalSales 64 | FROM online_retail 65 | GROUP BY Year, Month 66 | ORDER BY Year, Month; --------------------------------------------------------------------------------