Back to AGGREGATIONS & GROUP BY, ORDER BY

AGGREGATE FUNCTIONS

Understand aggregate functions like COUNT, SUM, AVG etc.

12 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Ready to continue?

Mark this lesson as complete when you're ready to proceed.

Key moments

  1. Aggregate Function Concept — Functions that perform calculations on a group of values to return a single output.
  2. COUNT() Function Usage — Demonstrating how to count all rows versus counting distinct values using the DISTINCT keyword.
  3. SUM() Function — Calculating the total value of a numeric column and noting the numeric data type requirement.
  4. AVG() Function — Calculating the average value, which is derived from SUM divided by the count of non-NULL values.
  5. MIN() Function — Finding the lowest value in a column, which works across multiple data types.
  6. MAX() Function — Finding the highest value in a column using the MAX() aggregate function.
PDF notes

Frequently asked questions

Why does COUNT(*) count rows with NULLs, but COUNT(column) doesn't?

COUNT(*) counts the existence of the row itself, while COUNT(column) checks the specific value in that column, which is ignored if NULL.

Can I use DISTINCT with MIN() or MAX()?

Yes, but it usually has no practical effect, as the minimum or maximum value remains the same whether duplicates are considered or not.

What happens if I try to SUM a text column?

The database will usually return an error or implicitly convert the text to zero, as SUM requires a numeric data type for calculation.

Are aggregate functions related to GROUP BY?

Yes, aggregates are often used with the GROUP BY clause, but this lesson focuses only on using them to summarize the entire table.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.