what is aggregate function in sql
Quick Scoop: An aggregate function in SQL is a function that takes multiple rows of data and returns a single summarized value, such as a total, average, minimum, maximum, or count.
What it does
Aggregate functions help you summarize data instead of looking at every row one by one.
They are commonly used for reporting, analytics, and dashboards, especially
with GROUP BY when you want results for each category.
Common examples
COUNT()counts rows or non-NULL values.
SUM()adds numeric values together.
AVG()calculates the average value.
MIN()returns the smallest value.
MAX()returns the largest value.
Simple example
sql
SELECT AVG(price) FROM products;
This returns one value: the average price across all rows in products.
With GROUP BY
sql
SELECT category, COUNT(*)
FROM products
GROUP BY category;
This gives a separate count for each category, which is how aggregate functions are often used in real queries.
Key idea
Think of aggregate functions as “summary” functions: they compress many rows into one result, making large datasets easier to understand.
If you want, I can also show the difference between aggregate functions and scalar functions in SQL.