Lesson 5: Aggregate Functions

30 min read Beginner Lesson 5 of 12 11.7k learners

What are Aggregate Functions?

Aggregate functions perform calculations on a set of values and return a single value. They are commonly used with the SELECT statement to summarize data.

COUNT()

The COUNT() function returns the number of rows that match a condition.

SQL
SELECT COUNT(*) AS total_customers
FROM customers;

SUM()

The SUM() function adds up the values in a numeric column.

SQL
SELECT SUM(order_amount) AS total_sales
FROM orders;

AVG()

The AVG() function calculates the average of a numeric column.

SQL
SELECT AVG(age) AS average_age
FROM customers;

MIN() and MAX()

MIN() finds the smallest value, and MAX() finds the largest value in a column.

SQL
SELECT MIN(order_amount) AS smallest_order,
       MAX(order_amount) AS largest_order
FROM orders;

Practice Quiz

Test your understanding of Aggregate Functions:

1. Which function counts the number of rows?
2. Which function calculates the average value of a column?
3. Which function finds the highest value in a column?
4. Which function adds up numeric values?
5. Which pair of functions gives the smallest and largest values?