🔍
👶 Kids📝 Blog About Contact 🚀 Get Started Free

SQL – Aggregate Functions

Summarize data across multiple rows using SQL aggregate functions like COUNT, SUM, AVG, MIN, and MAX.

Aggregate functions transform many rows of data into a single summary value. Instead of seeing 8 individual student scores, you can see the average. Instead of scrolling through 1,000 orders, you can see the total revenue. This is where SQL transitions from a data-retrieval tool into a genuine analytics engine.

All aggregate functions ignore NULL values (except COUNT(*)), which is an important detail. If a student’s score is NULL, it won’t drag down the average — but you should be aware of its absence when interpreting results.

The five core aggregates

FunctionWhat it returns
COUNT()Number of rows
SUM()Total of all values
AVG()Mean of all values
MIN()Smallest value
MAX()Largest value

Try It Yourself — Interactive SQL Editor

Edit the query below and click Run Query ▶ to see live results powered by SQLite running directly in your browser.

SQLite – edit & run
Results
← Click Run Query ▶ to see results

Key Points

  • Aggregate functions collapse many rows into one summary row
  • COUNT(*) counts all rows; COUNT(col) skips NULLs
  • Use ROUND() to control decimal places on AVG results
  • Combine with GROUP BY to get aggregates per category

Pro Tip from CodesCompiler: The best way to learn SQL is to break things intentionally — modify the query above, change the WHERE conditions, try different columns. Every error teaches you something the docs cannot.

In the next lesson, we continue exploring SQL’s powerful feature set to build your database mastery.