SQL AVG() for Beginners

In SQL, the AVG() function is an aggregate function that returns the average of all values in a given expression.

It can also be used to return the average of all distinct (unique) values in an expression.

The expression must be numeric (it cannot be character string, bit string, or datetime).

Below are some basic examples to demonstrate how it works.

Continue reading

SQL SUM() for Beginners

In SQL, the SUM() function is an aggregate function that returns the sum of all values in a given expression.

It can also be used to return the sum of all distinct (unique) values in an expression.

The expression must be numeric (it cannot be character string, bit string, or datetime).

Below are some basic examples to demonstrate how it works.

Continue reading

MIN() – Find the Minimum Value in a Column in MySQL

The MySQL MIN() function is an aggregate function that returns the minimum value from an expression.

Typically, the expression would be a range of values returned as separate rows in a column, and you can use this function to find the minimum value from the returned rows. If there are no matching rows, MIN() returns NULL.

For example, you can use this function to find out which city has the smallest population out of a list of cities.

Continue reading

MAX() – Find the Maximum Value in a Column in MySQL

The MySQL MAX() function is an aggregate function that returns the maximum value from an expression.

Typically, the expression would be a range of values returned as separate rows in a column, and you can use this function to find the maximum value from the returned rows. If there are no matching rows, MAX() returns NULL.

For example, you can use this function to find out which city has the largest population out of a list of cities.

Continue reading