File size: 2,774 Bytes
7124abf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SQL Analysis</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .sql-container {
            background-color: #f8f9fa;
            border-radius: 5px;
            padding: 20px;
            margin-bottom: 20px;
        }
        .result-container {
            background-color: #e9ecef;
            border-radius: 5px;
            padding: 15px;
            margin-top: 10px;
        }
        pre {
            background-color: #212529;
            color: #f8f9fa;
            padding: 10px;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <div class="container py-4">
        <h1 class="mb-4">Customers and Products Analysis</h1>
        
        <div class="sql-container">
            <h3>Top Customers by Revenue</h3>
            <pre>
SELECT c.customer_name, SUM(oi.quantity * oi.unit_price) AS total_revenue
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
JOIN order_items oi ON o.order_id = oi.order_id
GROUP BY c.customer_name
ORDER BY total_revenue DESC
LIMIT 10;
            </pre>
            <div class="result-container">
                <p>Results will appear here when run...</p>
            </div>
        </div>

        <div class="sql-container">
            <h3>Product Performance Analysis</h3>
            <pre>
SELECT p.product_name, 
       SUM(oi.quantity) AS total_units_sold,
       SUM(oi.quantity * oi.unit_price) AS total_revenue,
       AVG(oi.unit_price) AS avg_price
FROM products p
JOIN order_items oi ON p.product_id = oi.product_id
GROUP BY p.product_name
ORDER BY total_revenue DESC;
            </pre>
            <div class="result-container">
                <p>Results will appear here when run...</p>
            </div>
        </div>

        <div class="sql-container">
            <h3>Customer Purchase Frequency</h3>
            <pre>
SELECT c.customer_name,
       COUNT(DISTINCT o.order_date) AS purchase_days,
       COUNT(o.order_id) AS total_orders,
       COUNT(o.order_id) / COUNT(DISTINCT o.order_date) AS orders_per_day
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_name
ORDER BY orders_per_day DESC;
            </pre>
            <div class="result-container">
                <p>Results will appear here when run...</p>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>