SQL Functions - MAX, MIN, AVG
$count++; if($count == 1) { include "../mobilemenu.php"; } if ($count == 2) { include "../sharemediasubfolder.php"; } ?>
MAX function is used to get the largest value of the column name passed.
MIN function is used to get the smallest value of the column name passed.
AVG function is used to get the average value of the column name passed.
Imagine we have table called CUSTOMERS, with the following data:
FIRSTNAME
LASTNAME
AGE
COUNTRY
Rambo
Robert
25
Belgium
Mugambo
Satraj
37
Norway
Nagashekar
Rao
47
India
Tom
Harry
27
Brazil
Dana
Laura
21
Australia
Rambo
Fox
57
New Zealand
Giselle
Chivvi
87
Japan
SELECT MAX(AGE) from Customer
Result: 87In the above SELECT Clause, we used MAX function on AGE column to get the largest value.
Scenario 2: Get me the smallest age among the Customers. We can use MIN function for the above criteria.
SELECT MIN(AGE) from Customer
Result: 21In the above SELECT Clause, we used MIN function on AGE column to get the smallest value.
Scenario 3: Get me the average age of your Customer. We can use AVG function for the above criteria.
SELECT AVG(AGE) FROM Customer
Result: 43In the above SELECT Clause, we used AVG function on AGE column to get the average value.