Lesson 5: Aggregate Functions
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: