solution of lab performance

Upload: shams43

Post on 03-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Solution of Lab Performance

    1/2

    Lab Performance 1

    Solve the following Queries:

    1. Display the employee details hired between February 20, 1981 and May 20, 1981.

    Select ename, job,hiredate from emp

    Where hiredate between to_date(20-Feb-1981,DD-mon-yyyy) and to_date(20-May-

    1981,DD-mon-yyyy) order by hiredate;

    2. Display the employee name, department location for all employees who earn a commission.

    Select e.ename,d.dname,d.loc from emp e,dept d where e.deptno=d.deptno and e.comm is not null;

    3. Display the employee name along with their managers name.

    Select w.ename,m.ename from emp w, emp m

    Where w.mgr=m.empno;

    4. Display the employee name along with their salary who is getting the third lowest salary.

    select ename,sal from emp where sal = (Select min(sal) from emp

    where sal > (Select min(sal) from emp where sal >

    (Select min(sal) from emp)));

    5. Display all the employees with their managers name as well as employees who dont havemanager.

    Select w.ename,m.ename from emp w, emp m

    Where w.mgr=m.empno(+);

    6. Display the employees details along with their department details and their salary grades.

    Select e.ename,e.job,d.dname, e.sal, s.grade from emp e, dept d, salgrade s

    Where e.deptno=d.deptno and e.sal between s.losal and s.hisal

    7. Display the employee details who joined after BLAKE without using sub query.

    Select e.ename, e.hiredate, b.hiredate from emp e, emp B

    Where b.ename=BLAKE and e.hiredate > b.hiredate;

    8. Find the salaries greater than Jones salary without using sub query.

    Select e.ename, e.sal, b.sal from emp e, emp B

    Where b.ename=JONES and e.sal > b.sal;

    9. Write a query to display the department name, location name and number of employees and their

    rounded average salary for all employees as department name wise and location wise.

    Select d.dname, d.loc, count(*) , round(avg(sal), 2) Salary

    From emp e, dept d

  • 7/29/2019 Solution of Lab Performance

    2/2

    Where e.deptno=d.deptno

    Group by d.dname, d.loc;

    10. Create a query that will display the total number of employees and of that total the number who

    were hired in different years like 1980, 1981, 1982 and 1983.

    select count(*) Total, sum(decode(to_char(hiredate,'YYYY'), 1980,1,0)) "1980",sum(decode(to_char(hiredate,'YYYY'), 1981,1,0)) "1981",

    sum(decode(to_char(hiredate,'YYYY'), 1982,1,0)) "1982",

    sum(decode(to_char(hiredate,'YYYY'), 1983,1,0)) "1983",

    sum(decode(to_char(hiredate,'YYYY'), 1987,1,0)) "1987"

    from emp

    11. Create a matrix to display the job, the salary for that job based on department number and the total

    salary for that job for all departments giving each column an appropriate heading.

    select job "Job",sum(decode(deptno,10,sal)) "Dept 10",

    sum(decode(deptno,20,sal)) "Dept 20",

    sum(decode(deptno,30,sal)) "Dept 30",

    sum(sal) "Total"

    from empgroup by job;

    12. Write a query to display the employee name and Hiredate for all employee in the same department

    as Blake. Exclude blake.

    Select ename, hiredate from emp

    Where deptno=(Select deptno from emp where ename=BLAKE)

    And ename!=BLAKE;

    13. Write a query to display the name, department number and salary of any employee whosedepartment number and salary match the department number and salary of any employee who

    earns a commission.

    Select ename,deptno,sal from emp

    Where (sal,deptno) in (select sal,deptno from emp

    Where comm Is not NULL);

    14. Create a query to display the employees that earn a salary that is higher than the salary of allclerks. Sort the results on salary from highest to lowest.

    Select ename,job,sal from emp

    Where sal > all(Select sal from emp where job =CLERK)

    Order by sal desc;

    15. Display the name, Hiredate and day of the week on which the employee started. Order the results

    by the day of the week starting from Tuesday.

    Select ename,hiredate, to_char(hiredate,DAY) Days from emp

    Order by to_char(hiredate-2,D);