Sql Max, Min & Avg

Sql Max and Sql Min are two of the Sql functions that are used to get the extreme values.

Max is used to get the highest value while Min is to get the lowest value. The argument used in the function can be a column name, a function or combination of columns.

Unlike the functions SUM, AVG and COUNT, the DISTINCT clause does not affect the MIN and MAX result.

The syntax:

SELECT MAX(column_name),
       MIN (column_name)
FROM   table_name 

Example: Let's use the menu from my favorite noodle restaurant. They have this sub menu for Noodle. The task is to show the cheapest and the most expensive price.

2.1Singapore Fried Noodle9.00
2.2Beef Fried Soy Noodle8.50
2.3Claypot Noodle11.00
2.4Salted Fish Fried Noodle9.50
2.5Fried Koay Teow10.50

SQL Statement:

SELECT MAX(price) AS maxprice,
       MIN(price) AS minprice
FROM   contacts 


11.00 8.50

You can use Max and Min on a char field, it will compare the values alphabetically.

Sql Avg
Briefly, the usage is similar to Max and Min function. It calculates the average value of a numeric field.

The syntax:

SELECT AVG(column_name)
FROM   table_name 

The Avg function will ignore the Null value when it calculates the average. The Distinct has impact to the result.

Quick link. From here, you can learn the following:

Sql Select
The core of Sql, selecting data from table.

Sql Where
Conditionally selecting rows from table.

Sql Distinct
Eliminating duplicate values in the output.

Sql Count
Counting number of rows.

Sql Sum
Getting the sum of a field

Sql Order By
Sorting the output

Sql And Or
Connecting two or more conditions in the Where or Having clause.

Sql Group By
Grouping rows into sets.

Sql Having
To filter the result of aggregation

Sql Like
Pattern searching for conditions in Where or Having clause

Sql Between
Added to conditions to show results between two values.

Buy at AllPosters.com
A bend in the road is not the end of the road... unless you fail to make the turn

Positive Resources

All of us have at least two or three things that excite us. We could talk about these subjects for hours. Good news!. Did you know that Site Built It! can turn this type of deep interest and enthusiasm into a revenue-generating business?

Review some of the Site Build It! case studies and you'll absolutely discover something that ignites more positive ideas into your mind.

SBI! Video Tour

Invest the most
important 30 minutes
you will spend online.

Click, sit back, and
understand why SBI!
makes you succeed.