Learn SQL

SQL Aggregate Functions: COUNT, SUM, MIN, MAX, and AVG Explained

Aggregate functions turn many rows into useful summary values, which is the foundation of reporting, dashboards, and quick data checks.

Published 2026-05-09·Updated 2026-05-09

Summaries are the first reports

A table can contain hundreds, thousands, or millions of rows. Aggregate functions help you compress those rows into numbers you can understand quickly: counts, totals, extremes, and averages.

In SQL for Files, you can practice aggregates on sample sales data or run the same ideas against local files in your browser with DuckDB WASM.

COUNT and SUM answer how many and how much

COUNT tells you how many rows match a question. SUM adds numeric values such as revenue, quantity, or cost.

SELECT
  COUNT(*) AS sale_count,
  SUM(amount) AS total_amount
FROM sales
WHERE region = 'West';

COUNT(*) vs COUNT(column)

COUNT(*) counts rows. COUNT(column_name) counts rows where that column is not NULL.

MIN, MAX, and AVG describe the spread

MIN finds the smallest value, MAX finds the largest value, and AVG calculates the mean. Together, they give you a quick profile of a numeric column.

SELECT
  MIN(amount) AS smallest_sale,
  MAX(amount) AS largest_sale,
  AVG(amount) AS average_sale
FROM sales;

Aggregates usually return fewer rows

A plain aggregate query without GROUP BY usually returns one row. That one row represents a summary of all matching rows after WHERE filtering has been applied.

This is why aggregates are so useful for dashboards: one query can return the headline numbers your reader needs first.

Practice the Simple Aggregates chapter

  1. Use COUNT to count matching rows.
  2. Use SUM to total sales amounts.
  3. Combine COUNT and SUM for compact reporting.
  4. Finish with MIN, MAX, and AVG to profile values.

Continue in the editor

Open SQL for Files to add your own CSV, JSON, or Parquet files and try these examples locally in your browser.

Open editor