Aggregate functions in MySQL

In this post, we will see the aggregate functions in MySQL. MAX(), MIN(), COUNT(), AVG(), and SUM() are those functions used in MySQL. Also, we have one more function i.e DISTINCT(), which we have already covered in previous blog posts. These functions are applied to the column of the table, which returns the numeric value according to their functionality. Just the DISTINCT() function returns the unique values from that particular column.

We will see the syntax for each of the functions.

MAX() Function

This function returns the maximum value from the provided column. With the where clause we can provide a condition and get more specific results.

SELECT MAX(column_name)
FROM table_name
WHERE condition;

MIN() Function

This function returns the minimum value from the provided column.

SELECT MIN(column_name)
FROM table_name
WHERE condition;

COUNT() Function

This function returns the total number of records present in the provided column. We can get more specific results if we write conditions also.

SELECT COUNT(column_name)
FROM table_name
WHERE condition;

AVG() Function

This function returns the average of the values present in the provided column.

SELECT AVG(column_name)
FROM table_name
WHERE condition;

SUM() Function

This function returns the sum of total values present in the provided column.

SELECT SUM(column_name)
FROM table_name
WHERE condition;

Leave a Comment

Your email address will not be published. Required fields are marked *