Functions

 

MySQL’s aggregate function is used to perform calculations on multiple values and return the result in a single value like the average of all values, the sum of all values, and maximum & minimum value among certain groups of values. We mostly use the aggregate functions with SELECT statements in the data query languages.

Syntax :

function_name (DISTINCT | ALL expression)

 

  • First, we need to specify the name of the aggregate function.
  • Second, we use the DISTINCT modifier when we want to calculate the result based on distinct values or ALL modifiers when we calculate all values, including duplicates. The default is ALL.
  • Third, we need to specify the expression that involves columns and arithmetic operators.

 

There are various aggregate functions available in MySQL. Some of the most commonly used aggregate functions are summarised in the below table:

 

Aggregate Function Descriptions
count() It returns the number of rows, including rows with NULL values in a group.
sum() It returns the total summed values (Non-NULL) in a set.
average() It returns the average value of an expression.
min() It returns the minimum (lowest) value in a set.
max() It returns the maximum (highest) value in a set.
groutp_concat() It returns a concatenated string.
first() It returns the first value of an expression.
last() It returns the last value of an expression.