What are analytical functions in oracle sql?

Analytical functions:

It is known as window function. It performs calculations on the set of table rows which are related to the current row. Not like an aggregate function, it will return the single result for the group of rows. It will return a value for each row in the result set. It will return the aggregate results and don't group the result set. It will return the group value multiple times with each record. Group of rows is also called as window which is defined through the help of analytical clause.

select * from emp;






select deptno,count(*) EmployeeCount
from emp
group by deptno
order by 1;

We can find out the number of employees count in the each department.

select empno,ename,deptno,count(*) over (partition by deptno order by empno) as employee_count
from emp;

It will count the number of employees in each department. Within each partition, results are sorted as per empno which is specified in the over clause.
select empno,ename,deptno,count(*)employee_count from emp group by empno,ename,deptno
order by deptno;

By using an aggregate function, count will return the same value whenever there are the duplicate values. It will return one row per department for the number of employees which are associated with that department.







Comments

Popular posts from this blog

Explain oracle pl sql datatypes interview question and answer for fresher and experienced.

Difference between union and union all in oracle sql plsql

Difference between full join and cross join-oracle sql plsql