Aggregate Function in SQL

Aggregate functions perform a calculation on a set of column values and return a single value.

We will use the student to show how to use SQL aggregate functions:

Studentid Name Course City Marks
201 Nikita BCA Delhi 66
204 Sindhu BE Mysore 74
208 Sanvi BE Mysore 69
212 Sam M.tech Bangalore 65
220 Karthik MCA Mysore 70

The aggregate functions name are as follows:

  • COUNT() - Returns the number of rows
Select count(*) from student.

The result of this will be the number 5.

  • AVG() - Returns the average value 
Select avg(marks) from student.

The result of this will be the number 68.8

  • MAX() - Returns the maximum value in column
Select max(marks) from student.

The result of this will be the number 74.  

  • MIN() - Returns the smallest value in column
Select min(marks) from student.

The result of this will be the number 65.

  • SUM() - Returns the sum value of a column.
Select sum(marks) from student.

The result of this will be the number 344

Posted on by