E-Commerce Analytics Dashboard

Simulated PostgreSQL analytics for delivered orders, customers, products, and categories

Executive metrics

Showing: current month

Key performance indicators

Total Revenue
$0.00
Sum of delivered order line items
Average Order Value
$0.00
Total revenue / delivered orders
Delivered Orders
0
Orders with status = delivered
New Customers
0
Customers created in selected range

Top 5 Best-Selling Products

Ranked by quantity sold from delivered orders

Customer Growth Over Time

Monthly new customer count within selected date range

Category Performance

Revenue and units sold by product category from delivered orders

    SQL queries used to generate dashboard metrics

    This dashboard simulates a PostgreSQL e-commerce schema with: customers, orders, order_items, products, and categories. Revenue is calculated from delivered order line items using quantity * unit_price.

    1. Total Revenue
    SELECT
      COALESCE(SUM(oi.quantity * oi.unit_price), 0) AS total_revenue
    FROM orders o
    JOIN order_items oi
      ON oi.order_id = o.order_id
    WHERE o.status = 'delivered'
      AND o.order_date >= :start_date
      AND o.order_date < :end_date;
            
    2. Average Order Value
    WITH delivered_order_totals AS (
      SELECT
        o.order_id,
        SUM(oi.quantity * oi.unit_price) AS order_total
      FROM orders o
      JOIN order_items oi
        ON oi.order_id = o.order_id
      WHERE o.status = 'delivered'
        AND o.order_date >= :start_date
        AND o.order_date < :end_date
      GROUP BY o.order_id
    )
    SELECT
      COALESCE(AVG(order_total), 0) AS avg_order_value
    FROM delivered_order_totals;
            
    3. Top 5 Best-Selling Products
    SELECT
      p.product_name,
      c.category_name,
      SUM(oi.quantity) AS quantity_sold,
      SUM(oi.quantity * oi.unit_price) AS revenue
    FROM order_items oi
    JOIN orders o
      ON o.order_id = oi.order_id
    JOIN products p
      ON p.product_id = oi.product_id
    JOIN categories c
      ON c.category_id = p.category_id
    WHERE o.status = 'delivered'
      AND o.order_date >= :start_date
      AND o.order_date < :end_date
    GROUP BY
      p.product_id,
      p.product_name,
      c.category_name
    ORDER BY
      quantity_sold DESC,
      revenue DESC
    LIMIT 5;
            
    4. Customer Growth Over Time
    SELECT
      DATE_TRUNC('month', c.created_at)::date AS month,
      COUNT(*) AS new_customers
    FROM customers c
    WHERE c.created_at >= :start_date
      AND c.created_at < :end_date
    GROUP BY
      DATE_TRUNC('month', c.created_at)
    ORDER BY
      month;
            
    5. Category Performance
    SELECT
      c.category_name,
      COALESCE(SUM(oi.quantity * oi.unit_price), 0) AS revenue,
      COALESCE(SUM(oi.quantity), 0) AS units_sold
    FROM categories c
    LEFT JOIN products p
      ON p.category_id = c.category_id
    LEFT JOIN order_items oi
      ON oi.product_id = p.product_id
    LEFT JOIN orders o
      ON o.order_id = oi.order_id
     AND o.status = 'delivered'
     AND o.order_date >= :start_date
     AND o.order_date < :end_date
    GROUP BY
      c.category_id,
      c.category_name
    ORDER BY
      revenue DESC;