Reading Data
Aggregate Functions
Aggregate functions calculate one value from many rows.
SELECT COUNT(*) FROM students; -- 3
SELECT AVG(marks) FROM students; -- 85
SELECT MAX(marks), MIN(marks) FROM students;
SELECT SUM(amount) FROM orders WHERE status = 'paid';| Function | Returns |
|---|---|
COUNT() | Number of rows |
SUM() | Total |
AVG() | Average |
MIN() / MAX() | Smallest / largest |