Monday, January 16, 2012

MySQL Aggregate Functions

In our database, we can use aggregate functions or calculating actions on columns or fields to include but not limited to COUNT, MAX, MIN, SUM among others.

The following are the commonly used aggregate functions of SQL:

SUM() - computes the total of all rows or records;
AVG() - computes the average of all rows for a given numeric column or field;
COUNT(*) - counts the total number of records satisfying the condition.
MAX() - determines the largest value in a column.
MIN() - determines the smallest value in a column


To apply these functions on the table above, we can display the number of students whose age is below 15 using the SQL command below.

SELECT count(*) FROM  STUDENT where age<15

To display  oldest age among all records, we can use the MAX() function.


To display the average age, you can use the AVG function.

No comments: