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 DefinitionAggregate functions perform calculations on multiple input values and return a single output value.
  2. Need for AggregationReal-world examples like Google Maps ETA and sensor data show the necessity of summarizing large data sets efficiently.
  3. Core PropertiesAggregate functions ignore NULL values, except for the COUNT function, and are enhanced by GROUP BY and HAVING clauses.
  4. Five Functions ListedSQL provides five standard aggregate functions: COUNT, SUM, AVERAGE, MINIMUM, and MAXIMUM.
  5. COUNT FunctionThe COUNT function returns the number of rows and works on both numeric and non-numeric data types.
  6. COUNT DISTINCTUsing the DISTINCT keyword inside COUNT calculates the number of unique values in a specified column.
  7. SUM FunctionThe SUM function calculates the total of a column and works exclusively on numeric data types.
  8. AVG FunctionThe AVG function calculates the average value and can also be modified using the DISTINCT keyword.
  9. MIN and MAX FunctionsMIN returns the lowest value and MAX returns the highest value in the selected column, both working on non-null values.
PDF notes

Frequently asked questions

Why do aggregate functions ignore NULL values?

They are designed to perform calculations on valid data points. NULL represents missing or unknown data, so it is excluded from the calculation (except for COUNT(*)).

Do MIN and MAX only work on numeric data?

While demonstrated with salary, MIN and MAX can also work on non-numeric data types, returning the alphabetically or chronologically lowest/highest value.

How do GROUP BY and HAVING relate to aggregate functions?

These clauses enhance aggregates by allowing you to calculate summary values for specific subsets of data, rather than summarizing the entire table at once.