MySQL + SQL · Lesson 55
Aggregate Functions in MySQL
What are Aggregate Functions?
Aggregate functions work on many rows and return a single summary value — like a total or average.
The Five Functions
| Function | Returns |
|---|---|
| COUNT() | number of rows |
| SUM() | total |
| AVG() | average |
| MAX() | highest |
| MIN() | lowest |
Examples
SELECT COUNT(*) FROM students;
SELECT SUM(marks) FROM students;
SELECT AVG(marks) FROM students;
SELECT MAX(marks), MIN(marks) FROM students;Each query returns one summary number for the whole table.
Summary
- Aggregate functions summarise many rows into one value.
- COUNT, SUM, AVG, MAX, MIN.