Skip to content

Aggregatefunctions

AGGREGATE FUNCTIONS :

An aggregate function performs a calculation on a set of values, and returns a single value. aggregate functions ignore null values. Aggregate functions are often used with the GROUP BY clause of the SELECT statement

MAX() :

It returns maximum value in the expression.

1
select max(expression) from tablename

ex:

1
select max(sal) as max_salary from emp

MIN() :

It returns Minimum value in the expression

1
select min(expression) from tablename

ex:

1
select min(sal) as min_sal from emp 

SUM():

Returns the sum of all the values, in the expression. SUM can be used with numeric columns only.

1
select sum(expresion)  from tablename

ex:

1
select sum(sal) as total_sal from emp 

AVG():

This function returns the average of the values in a group

1
SELECT avg(expression) from tablename

ex:

1
select avg(sal) as average from emp

COUNT():

This function returns the number of items found in a group. COUNT operates like the COUNT_BIG function. These functions differ only in the data types of their return values. COUNT always returns an int data type value. COUNT_BIG always returns a bigint data type value.

1
SELECT count(expression) from table 

ex:

1
2
3
select count(*) from emp 
or 
select count(sal) from emp

count(*) ---consider the null values as count count(columnname)----does not consider the null values as count