...

/

Ask Bigger Questions

Ask Bigger Questions

Learn how to summarize and group data using SQL aggregates like COUNT, AVG, SUM, and GROUP BY.

As data analysts, our goal goes beyond simply retrieving rows from a database; we’re here to uncover stories within the data. We need to ask big-picture questions like:

  • How many customers placed an order last week?

  • What’s the average salary in each department?

  • Which product category brought in the most revenue?

These are not answered by looking at individual records. Instead, we use aggregate functions, which constitute special SQL tools that calculate metrics like totals, averages, and counts across multiple rows.

In this lesson, we will show how to use aggregate functions to extract actionable insights from data. Let’s get started by understanding the core aggregate functions in SQL.

Count with confidence

Before we can build a meaningful chart or share a report, we need to ensure the data is complete and trustworthy. One of the first tools we turn to as data analysts is the COUNT() function which helps us check what we’re working with right from the start.

We use it to count rows, identify missing values, and confirm that the data loaded correctly. It’s a simple function, but an essential one. By verifying completeness early on, we lay the groundwork for analysis that we and others can trust.

Syntax

The following is the syntax to use COUNT() function:

SELECT COUNT(*) FROM table_name;
SELECT COUNT(column_name) FROM table_name;
Syntax of COUNT function
  • COUNT(*): Counts all rows in the table, including those with NULL values in any column..

  • COUNT(column_name): ...