Customers and Products Analysis

Top Customers by Revenue

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;
            

Results will appear here when run...

Product Performance Analysis

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;
            

Results will appear here when run...

Customer Purchase Frequency

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;
            

Results will appear here when run...