COUNT()
: Returns the number of rows.SUM()
: Returns the sum of a numeric column.AVG()
: Returns the average value of a numeric column.MIN()
: Returns the smallest value.MAX()
: Returns the largest value.Let’s assume we have a table sales
and we want to calculate the total sales (SUM
) from all records in the table. Here’s the query:
SELECT SUM(amount) AS total_sales
FROM sales;
In this example:
SUM(amount)
function adds up all the values in the amount
column.total_sales
.GROUP BY
: These functions are often used in combination with GROUP BY
to group rows and calculate summary statistics.MySQL Aggregate Functions are essential tools for performing calculations on multiple rows of data. They simplify complex queries by providing summary statistics like total, average, and counts. Understanding how to use aggregate functions is crucial for analyzing and reporting on data effectively.