Quick answer

SQL aggregate functions summarize data across multiple rows and return a single value.

The most common ones are:

  • COUNT() → how many rows
  • SUM() → total value
  • AVG() → average value
  • MIN() → smallest value
  • MAX() → largest value
Tip: If your question sounds like “how many,” “total,” or “average,” you probably need an aggregate function.

In this guide

Sample table

Imagine this employees table:

employee_id name department salary city
1AnaSales62000Chicago
2BenIT78000Dallas
3ChrisHR56000Chicago
4DanaIT85000Denver
5EvanSales59000Austin
We’ll use this table for all examples so you can clearly see how each function works.

COUNT()

COUNT() tells you how many rows exist.

SELECT COUNT(*) AS total_employees
FROM employees;

This returns the total number of rows in the table.

COUNT(*) counts all rows, even if some columns contain NULL values.

SUM()

SUM() adds up numeric values.

SELECT SUM(salary) AS total_salary
FROM employees;

This returns the total salary across all employees.

Use SUM() for totals like revenue, expenses, quantities, or salaries.

AVG()

AVG() calculates the average value.

SELECT AVG(salary) AS avg_salary
FROM employees;

This returns the average salary.

AVG() ignores NULL values when calculating the average.

MIN() and MAX()

MIN() returns the smallest value. MAX() returns the largest value.

SELECT MIN(salary) AS lowest_salary,
       MAX(salary) AS highest_salary
FROM employees;

This shows the lowest and highest salaries in the table.

Using aggregate functions with GROUP BY

Aggregate functions become much more powerful when combined with GROUP BY.

SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department;

This returns one row per department with a count of employees.

Think of it as: “Group first, then summarize each group.”

How NULL values behave

  • COUNT(*) counts all rows
  • COUNT(column) ignores NULL values
  • SUM() and AVG() ignore NULL values
NULL does not mean zero. It means “no value,” and most aggregate functions skip it.

When to use aggregate functions

Use COUNT: number of users, orders, or rows
Use SUM: total revenue, total cost, total quantity
Use AVG: average salary, average order value
Use MIN/MAX: lowest/highest values
If your question involves summarizing data instead of listing individual rows, use aggregate functions.

Common mistakes

  • Using aggregate functions without understanding GROUP BY
  • Mixing normal columns and aggregates without grouping properly
  • Forgetting that NULL values are ignored
  • Using COUNT(column) and expecting it to count NULL rows
If you combine normal columns with aggregate functions, SQL usually requires those columns to be included in GROUP BY.

Practice questions

1. Count how many employees exist
2. Find total salary across all employees
3. Find average salary
4. Find highest and lowest salary
5. Count employees per department using GROUP BY

Bottom line

Aggregate functions let you summarize data quickly and answer high-level questions.

Quick memory trick: COUNT = how many, SUM = total, AVG = average, MIN/MAX = extremes.

Related SQL tutorials

SQL Hub
Start here for all SQL tutorials.
GROUP BY
Learn how to group rows before applying aggregate functions.
SQL Joins Explained
Learn how to combine tables before summarizing data.
SELECT Statement
Learn how to retrieve data before summarizing it.