Sql is having so many predefined function and aggregate functions are also part of it. These functions are used to summarize the output. For example, if we want to sum any column, find out the maximum or minimum etc. then we can use these functions.

I am taking following table for this article

aggregate function in sql

		Figure 1

Type of Aggregate functions

We have following types of aggregate function

Count

Count function is used to count given row. for example, we want to count how many employees are taking salary then we will use count function with salary.

select count(salary) as count from employee

it will return following result

count aggregate function

		Figure 2

Count(*)

This function will also use to count the given row but here * represents the all row. So if we apply this function it will return following count

select count(*) as count from employee

		

it will return the following output

count(*) aggregate function

		Figure 3

Difference between count and count (*)

 Count function require column to count data but count(*) will count all rows

 Count function do not count NULL values in column but count(*) will count all rows whether any column having null or not.

Sum

Sum aggregate function is used to addition of the particular column. For example, if we need to sum all salary then we will use following query

select sum(salary) from employee

		

it will show following output

sum aggregate function

		Figure 4

Max

Max function is used to display maximum value of the column

select max(salary) from employee
		

max aggregate function

		Figure 5

Min

Min function is used to display minimum value of the column

select min(salary) from employee

		
min aggregate function

		Figure 6