Tuesday 20 August 2013

Aggregate Functions in oracle

Aggregate functions are statistical functions such as count, min, max etc. They are used to
compute a single value from a set of attribute values of a column: count Counting Rows
Example: How many tuples are stored in the relation EMP?
select count(*) from EMP;
Example: How many different job titles are stored in the relation EMP?
select count(distinct JOB) from EMP;
max Maximum value for a column
min Minimum value for a column
Example: List the minimum and maximum salary.
select min(SAL), max(SAL) from EMP;
Example: Compute the difference between the minimum and maximum salary.
select max(SAL) – min(SAL) from EMP;
sum Computes the sum of values (only applicable to the data type number)
Example: Sum of all salaries of employees working in the department 30.
select sum(SAL) from EMP
where DEPTNO = 30;
avg Computes average value for a column (only applicable to the data type number)
Note: avg, min and max ignore tuples that have a null value for the specified
attribute, but count considers null values.

No comments:

Post a Comment