...

/

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 scientists, 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:

  • 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—special SQL tools that calculate metrics like totals, averages, and counts across multiple rows.

This lesson 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

In data science, understanding how much or how many is often the first step in quantifying patterns. Whether looking at total users, orders placed, or records with missing values, the COUNT() function is our go-to tool for tallying rows.

The COUNT() function in SQL returns the number of rows that match a specified condition. It can count all rows, non-null values of a column, or rows filtered by a WHERE clause.

Syntax

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

SELECT COUNT(*) FROM table_name;
SELECT COUNT(column_name) FROM table_name;
  • COUNT(*): Counts all ...