Lesson 4: Aggregate Functions: COUNT, SUM, AVG, MIN, MAX

05 Jul 2026 1 min Swarnil Singhai

Aggregate functions collapse many rows into one summary value — the foundation of every dashboard metric.

Real-time example

A sales dashboard shows total revenue, average order value, and the largest single order — all from one orders table.

SELECT
    COUNT(*) AS total_orders,
    SUM(amount) AS revenue,
    AVG(amount) AS avg_order_value,
    MAX(amount) AS biggest_order
FROM orders
WHERE created_at >= '2026-07-01';

What's happening

Each function scans the filtered rows once and produces a single number — COUNT, SUM, AVG, MIN, MAX all work this way.

Aggregate functions ignore NULL values by default — a common surprise if your data has missing amounts.

Advertisement