Learn to perform calculations on sets of data with COUNT, SUM, AVG, MAX, MIN.
Aggregate functions are a special type of function in SQL that perform a calculation on a set of rows and return a single, summary value. They are essential for data analysis and reporting and are most commonly used with the `GROUP BY` clause to calculate metrics for different categories. The five most common aggregate functions are: `COUNT()`, `SUM()`, `AVG()`, `MAX()`, and `MIN()`. `COUNT(column_name)` returns the number of non-NULL rows in the specified column. `COUNT(*)` is a special case that counts all rows in the group or table, regardless of NULL values. `SUM(column_name)` calculates the total sum of all values in a numeric column. It ignores NULL values. `AVG(column_name)` calculates the average value of a numeric column. It also ignores NULL values in its calculation. `MAX(column_name)` returns the largest value from the specified column. It can be used on numeric, text, or date columns. `MIN(column_name)` returns the smallest value from the specified column. For example, in a sales database, you could use these functions to find the total number of orders (`COUNT`), the total revenue (`SUM`), the average order value (`AVG`), and the highest (`MAX`) and lowest (`MIN`) sale amounts. When used without a `GROUP BY` clause, they operate on the entire table and return a single row of results.