Skip to content

Aggregations — GROUP BY, COUNT, SUM, AVG

Master aggregation functions, GROUP BY, and HAVING to summarize and analyze your data effectively.

13 min readdatabases, sql, aggregations, group-by

Raw data is just rows. Useful data is answers. "How many orders did we get this month?" "What's the average order value?" "Which product category generates the most revenue?" Aggregation functions are how you turn thousands of rows into the numbers that actually matter.

The Core Aggregation Functions

SQL gives you five fundamental aggregation functions. Each one collapses multiple rows into a single value.

COUNT — How Many?

-- How many orders do we have?
SELECT COUNT(*) FROM orders;
-- Result: 847
 
-- How many orders have a shipping address?
SELECT COUNT(shipping_address) FROM orders;
-- Result: 812

The difference matters: COUNT(*) counts all rows. COUNT(column_name) counts only rows where that column is not NULL. Use COUNT(DISTINCT column_name) to count uniqu

This lesson is part of the Guild Member curriculum. Plans start at $29/mo.