0% found this document useful (0 votes)
21 views

Analytical Function

The document demonstrates various analytical functions in Oracle including ROLLUP, RANK, DENSE_RANK, FIRST_VALUE, LAST_VALUE, and LEAD. It creates an employee table, inserts sample records, and runs queries using these functions to analyze and summarize data like salaries by ID, name, and age.

Uploaded by

Ajit Panada
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Analytical Function

The document demonstrates various analytical functions in Oracle including ROLLUP, RANK, DENSE_RANK, FIRST_VALUE, LAST_VALUE, and LEAD. It creates an employee table, inserts sample records, and runs queries using these functions to analyze and summarize data like salaries by ID, name, and age.

Uploaded by

Ajit Panada
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Analytical Function:

1) Create table.
create table employee1(Emp_ID number(3) primary key,Emp_Name varchar2(20),Age
number(2),Salary number(20));
2) Insert records into the table
insert into employee1 Values(1,'Abc',30,30000);
insert into employee1 Values(2,'Def',28,30000);
insert into employee1 Values(3,'Ghi',24,25000);
insert into employee1 Values(4,'Jkl',32,40000);
insert into employee1 Values(5,'Mno',34,50000);
insert into employee1 Values(6,'Pqr',40,50000);
insert into employee1 Values(7,'Stu',38,35000);
insert into employee1 Values(8,'Vwx',34,35000);
insert into employee1 Values(9,'Zya',32,30000);
insert into employee1 Values(10,'Bcd',34,40000);
3)ROLL UP operation
select Emp_ID,Salary,Age from employee1 group by rollup(Emp_ID,Salary,Age);

select Emp_ID,Salary,SUM(Salary) from employee1 group by rollup(Emp_ID,Salary);

4)PARTIAL ROLL UP
select Age from employee1 group by Salary,rollup(Age,Emp_Name);

5) Rank
Select Rank(30000) within group(ORDER BY Salary) from employee1;

6)Dense_Rank
Select DENSE_Rank(55000) within group(ORDER BY Salary)"RANK" from employee1;

7)
First:
select Emp_ID,Salary,first_value(Salary) OVER(ORDER BY Salary ASC) as LowSal from
employee1;

8)
Last:
select Emp_ID,Salary,last_value(Salary) OVER(ORDER BY Salary DESC) as highSal from
employee1;

9)
Lead:
select Emp_ID,Emp_Name,Age,LEAD(Age,20) OVER (ORDER BY Salary)as Sal from
employee1;

You might also like