Mastering SQL Aggregation Functions: A Comprehensive Guide with Examples

SQL Fundamentals
5 min readSep 23, 2023

Aggregation functions play an important role in SQL when it comes to summarizing and analyzing data. They allow us to calculate statistical metrics, perform calculations on groups of data, and gain meaningful insights.

In this article, we will explore the 10 most commonly used MYSQL aggregation functions such as COUNT, SUM, AVG, MIN, MAX, ROUND, GROUP BY, WITH ROLLUP, LIMIT, HAVING with practical examples.

1. COUNT

It returns the number of non-null values in a column
or the number of rows in a table.

Example:
SELECT COUNT(*) AS total_rows
FROM table_name;

SELECT COUNT(column_name)
FROM table_name;

-- How many rows are in the authors table?

SELECT COUNT(*) AS total_rows
FROM authors;
-- How many authors are in the dataset?

SELECT COUNT(DISTINCT au_id) AS number_of_authors
FROM authors;
-- How many authors live in either San Jose or Salt Lake City?
SELECT COUNT(au_id)
FROM authors
WHERE city IN ("San Jose", "Salt Lake City");
-- How many stores are based in California state (CA)?

SELECT…

--

--