Course contentsShow
← Data Science
Lesson 889 of 2,14523. SQL Aggregation and GroupingFree lesson

Aggregate Functions Without GROUP BY

Using aggregate functions on entire tables to produce single-row summary statistics across all data.

Aggregate Functions Without GROUP BY

You'll learn how to use aggregate functions to summarize an entire table into a single value.

The Core Idea

When you use an aggregate function like COUNT(), SUM(), or AVG() without a GROUP BY clause, SQL treats your entire table as one big group. The result? A single row containing summary statistics that describe all the data in that table.

Think of it like asking "What's the average height of everyone in the room?" instead of "What's the average height per team?" The first question gives you one number; the second would require grouping.

How It Works

When you write:

SELECT AVG(salary)
FROM employees;

SQL scans every row in the employees table, calculates the average salary across all employees, and returns exactly one row with one value.

You can combine multiple aggregates in the same query:

SELECT 
    COUNT(*) AS total_employees,
    AVG(salary) AS average_salary,
    MAX(salary) AS highest_salary,
    MIN(salary) AS lowest_salary
FROM employees;

This returns a single row containing four summary statistics about the entire workforce—total count, average pay, highest earner, and lowest earner.

When to Use This Pattern

Aggregate functions without GROUP BY are perfect for:

  • Dashboard summary cards (total sales, average rating)
  • Quick data quality checks (row counts, null percentages)
  • Overall performance metrics across your entire dataset

Common Pitfall

You cannot mix regular columns with aggregate functions without GROUP BY. This would fail:

SELECT name, AVG(salary) FROM employees;  -- ERROR!

SQL wouldn't know which single name to display alongside the averaged salary of everyone.

Key Takeaway: Aggregate functions without GROUP BY collapse your entire table into a single summary row, perfect for high-level metrics and quick insights across all data.