Anda di halaman 1dari 5

DBMS Assignment 4

Vikrant Shinde (50245119)

1) select E.last_name , J.job_title, D.department_name ,JH.start_date


from Jobs J , Departments D , Job_History JH
where J.job_id= JH.job_id
and JH.department_id=D.department_id
and E.employee_id= JH.employee_id
and TO_CHAR(Start_date,YYYY) in (2000,2001,2002,2003,2004,2005)

2) select E.employee_id ,JH.job_id ,J.job_title


from Jobs J , Employees E , Job_History JH
where J.job_id= JH.job_id
and E.employee_id= JH.employee_id
and E.salary >15000;

3) select E.First_name|| ||E.Last_name


from Employees E , Employees M
where E.manager_id=M.employee_id
and E.hire_date<M.hire_date;

4) select J.job_title,E.employee_id , JH.end_date-JH.start_date


from Jobs J , Employees E , Job_History JH
where J.job_id= JH.job_id
and E.employee_id= JH.employee_id
and JH.department_id=30;

5) select E.last_name, J.job_title, E.commission_pct


from Jobs J , Employees E
where E.job_id=J.job_id
and E.commission_pct is not null;

6) select E.*
from Employees E
where E.salary = (select max(salary) from Employees M where
M.department_id=E.department_id);

7) select D.department_name, M.first_name|| ||M.last_name, L.city


from Employees E , Employees M,Departments D, Location L
where E.manager_id=M.employee_id
and E.department_id= D.department_id
and D.Location_id =L.Location_id
8) select E.First_name, E.last_name , J.job_title, name ,JH.start_date ,JH.end_date
from Jobs J , Job_History JH
where J.job_id= JH.job_id
and JH.department_id=D.department_id
and E.employee_id= JH.employee_id
and E.commission_pct is null;

9) select E.*
from Employees E
where E.salary = (select max(salary) from Employees M where
M.department_id=E.department_id);

10) Functions with example:


Rank()
It is an aggregate function which is used to calculate rank of a value in a group of values. The
return type of this function is a number.

For eg.
select empno , Ename,sal ,rank() over (order by sal) from emp ;
Dense rank ()
It is an aggregate function which works on similar lines of rank () how ever it calculates the
value of rank in an ordered way and assigns consecutive ranks.

For Eg.

select empno , Ename,sal ,dense_rank() over (order by sal) from emp ;


Lead()
Lead function is used to access data from the succeeding row for further computations.

For Eg.
select empno , Ename,sal ,lead(sal,1,0)over(order by sal) from emp ;

Lag ()
It is an analytical function which is used to access data from the previous row to perform
computations

select empno , Ename,sal ,lag(sal,1,0)over(order by sal) from emp ;

Anda mungkin juga menyukai