Lesson 15 / 28
Aggregate Functions
COUNT, SUM, AVG, MIN and MAX summarize a column.
The five common ones
COUNT, SUM, AVG, MIN, MAX collapse many rows into a single summary value.
SELECT COUNT(*) AS total_orders,
SUM(amount) AS revenue,
AVG(amount) AS avg_order,
MAX(amount) AS biggest
FROM orders;
Output:
total_orders | revenue | avg_order | biggest 3 | 4500.00 | 1500.00 | 2000.00
COUNT(*) vs COUNT(column)
COUNT(*) counts all rows; COUNT(column) skips rows where that column is NULL.
Quick check: Which counts only non-NULL values in a column?
- COUNT(*)
- COUNT(column_name)
- SUM(column_name)
Answer
COUNT(column_name) — COUNT(column) ignores NULLs in that column; COUNT(*) counts every row.