🗃️Aggregate Function
Also known as SQL Aggregate Function, COUNT, SUM, AVG
A SQL tool that turns lots of rows into one number, like a sum.
Think of it like
It is like a till at the end of the day. It turns a pile of sales into one total.
Example
Emma runs SELECT COUNT(*) FROM orders and sees 1,204. She runs AVG(total) and learns the average order size.
Why it matters
Totals, counts and averages are what most reports show. These functions work them out inside the database, which is fast.
Definition
Example code
sql
SELECT COUNT(*), AVG(total), MAX(total)
FROM orders;Common mistake
Key takeaways
- 1Many in, one out. A whole set of rows becomes one value.
- 2Five common ones. COUNT, SUM, AVG, MIN, MAX.
- 3Per group with GROUP BY. One answer for each group.