All the course material is stored in the SQL Crash Course repository.
Hi everyone! Once again, Cornellius and Josep Ferrer from DataBites here👋.
Let’s continue our SQL Crash Course journey!📚
Whether this is your first time or you need a refresher, we're excited to discuss seven key SQL topics together!
Each topic will be broken down into engaging posts published on Non-Brand Data and DataBites.
📚 Previously in SQL Basics…
Remember last Thursday we already saw
📌 #3 Relational Data & Models by
in DataBites📌 #4 Basic Commands by me in Non-Brand Data.
Today, two fresh issues just dropped:
📌 #5 Filtering and Sorting, where Josep will focus on two essential commands: ORDER BY
and LIMIT
📌 #6 Aggregate Functions – in which I will walk you through the most commonly used aggregates like SUM
, AVG
, and COUNT
With these, we wrap up Section 2: SQL Basics 🎉
Next week, we jump into Intermediate SQL with four exciting topics:
JOINS (INNER, LEFT, RIGHT, FULL)
UNION & UNION ALL
CASE Expressions
Functions (String, Date, Numeric)
So don’t miss out—let’s keep the SQL momentum going!
SQL Aggregation Functions📚
In our earlier courses, we explored SQL and discovered how to filter it effectively!
Another important concept that every data professional should get familiar with when using SQL is aggregation functions!
🔥Aggregate functions are SQL commands to summarize multiple data rows into a single value.
They answer questions like:
“What are the total sales this month?”
“How many users signed up last week?”
“What’s the average price of our products?”
They’re essential for data analysis, reporting, and decision-making as humans find it hard to understand data in its raw form.
In this course, we will guide you in exploring various SQL Aggregate functions, which are:
SUM to add up numeric values in a column
AVG to calculate the average of numeric values
COUNT to counting rows or non-
NULL
values in a columnMIN/MAX to find the smallest (
MIN
) or largest (MAX
) value in a columnGROUP BY to segment data into groups
HAVING to filter results after aggregation (unlike
WHERE
, which filters rows before aggregation).
Ready to understand the aggregate function? Let’s begin.
✅SUM Aggregate Function
The SUM function answers the question, “What’s the total value?”
What It Does
Adds up numeric values in a column.
Ignores
NULL
values.
The query is present as follows:
SELECT SUM(points) AS total_points
FROM interactions;
The SUM function is always used in the SELECT clause, as it calculates totals from numeric columns.
✅AVG Aggregate Function
The AVG function answers the question: “What’s the average value?”
What It Does
Calculates the average of numeric values.
Excludes
NULL
values.
The basic query to use the AVG function is as follows:
SELECT AVG(points) AS average_points
FROM interactions;
AVG helps us understand data trends (e.g., average salary, order value). Always ensure your column contains numeric data; use ROUND if you need cleaner results.
For example, you can combine AVG and ROUND in the following query:
SELECT ROUND(AVG(points),2) AS average_points
FROM interactions;
✅ COUNT Aggregate Function
The COUNT function answers, “How many entries are there?”
What It Does
Counts rows or non-
NULL
values.
The query to count all the available rows is as follows:
SELECT COUNT(*) AS total_interactions
FROM interactions;
However, if you want to exclude the NULL
values and only in the certain column, then you can use the following query:
SELECT COUNT(points) AS count_points
FROM interactions;
Use the COUNT if you need all the information on your data.
✅ MIN/MAX
The MIN and MAX function answers: “What’s the smallest and biggest value?”
What It Does
Finds the minimum value in a column (MIN).
Finds the maximum value in a column (MAX).
You can easily run the query for MIN and MAX together using a simple syntax like this:
SELECT MIN(published_at) AS earliest_post,
MAX(published_at) AS latest_post
FROM posts;
MIN and MAX work with numbers, dates, and text (e.g., alphabetically ordered first). You can use them to identify starting points, like the earliest date or lowest price.
✅ GROUP BY
The GROUP BY clause answers, “How do I summarize data by groups or categories?”
What It Does
Groups of rows with the same values are divided into summary rows.
Used with aggregate functions (e.g.,
SUM
,AVG
) to calculate values per group
The clause example can be used like the one below.
SELECT type_of_interaction, COUNT(*) AS interactions_count
FROM interactions
GROUP BY type_of_interaction;
GROUP BY must include all non-aggregated columns in the SELECT clause. For example, selecting published_at and MAX(published_at) will not work. You must group by category.
✅ HAVING
The HAVING clause answers “How do I filter grouped results?”
What It Does
Filters groups after aggregation (unlike WHERE, which filters rows before aggregation).
Works with aggregate functions (e.g., SUM, COUNT).
Here’s a simple way to explore interaction types that happen more than once using the HAVING clause:
SELECT type_of_interaction, COUNT(*) AS interactions_count
FROM interactions
GROUP BY type_of_interaction
HAVING COUNT(*) > 1;
Use HAVING to filter aggregated results to acquire the data you want.
And now? It is your turn to play in our SQL playground with all the aggregated functions we learned.
👉🏻 SQL playground with Aggregation Function
That’s everything you need to understand about the Aggregation Function!
You're doing an amazing job! Stay tuned as we move deeper into SQL! 👩💻👨💻
How to Get Started 🚀
Over the coming weeks, we’ll guide you through:
✅ SQL Fundamentals
✅ Intermediate SQL
✅ Advanced SQL
✅ Database Operations
✅ Writing Efficient Queries
What’s Next?➡️
This is the first of many posts about the upcoming SQL Courses. It will only explain what SQL is in its crude form.
To get the full experience and fully immersed in the learning:
👉Subscribe to Databites.tech (By Josep)
👉Subscribe to Non-Brand Data (By Cornellius)
👉Check out the SQL Crash Course GitHub repo
👉Share with your friend and whoever needs it!
🗓️ Every Thursday, you will have two new issues in your inbox!
Let’s dive in and make SQL less scary, more fun, and way more useful! 🚀
Josep & Cornellius