Aggregate Functions

One of the key features of SQL is its ability to perform aggregate functions and group data, allowing us to extract meaningful insights from large datasets. In this article, we'll dive into some of the most commonly used aggregate functions and explore how grouping can enhance data analysis.

COUNT

The COUNT function is fundamental for understanding the size of a dataset.

Returns how many rows are in a column

If you apply it to a specific column, it returns non-NULL values.

SUM

Adds values in a particular column.

Sum only works with numeric values.

MIN & MAX

Usually helps find the lowest and highest values respectively

They work not only with numeric data but also with non-numeric values like dates and strings. Additionally, these functions ignore NULL values, allowing you to focus on the actual data ranges.

Min lowest number, earliest date and alphabetically whilemax is opposite.

AVG

calculates the average or mean of all rows in a column.

GROUP BY

Used to aggregate data within subsets of the data.

Any column not in the SELECT statement should be in the GROUP BYclause.

If the grouping column contains a row with NULL values it will be returned as a group.

goes between WHERE and ORDER BY

You can group by multiple columns at once.

HAVING

While the WHERE clause filters data before aggregation, the HAVING clause filters data after aggregation. It helps you narrow down results based on aggregated conditions.

vamos a practicar