DBMS LAB : Cycle-IV
Lab Cycle - IV Queries
1.Create a view, which contain employee names and their manager names working in sales department.
--->create view v1 as (select e.ename,n.ename as managername from emp e,emp n,dept d where e.mgr=n.empno and e.deptno=d.deptno and d.dname='sales');
View created.
=============================================================================
2. Update the employee salary by 25%, whose experience is greater than 10 years.
---> update emp set sal=sal+(sal*0.25) where round(months_between(sysdate,hiredate)/12)>10;
14 rows updated.
=============================================================================
3. Delete the employees, who completed 32 years of service.
---> delete from emp where round(months_between(sysdate,hiredate)/12)>32;
0 rows deleted.
=============================================================================
4. Determine the minimum salary of an employee and his details, who join on the same date.
--->select * from emp where sal in(select min(sal) from emp group by hiredate having count(hiredate)>=2);
Output:
| EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO |
| 7900 | james | clerk | 7698 | 03-DEC-81 | 1187.5 | 30 |
=============================================================================
5. Determine the count of employees, who are taking commission and not taking commission.
---> select count(comm) nottakingcommission,count(empno)-count(comm) as takingcommission from emp;
Output:
| NOT TAKING COMMISSION | TAKING COMMISSION |
| 4 | 10 |
=============================================================================
6. Determine the department does not contain any employees.
---> select deptno,dname from dept where deptno not in (select deptno from emp);
Output:
| DEPTNO | DNAME |
| 40 | operations |
=============================================================================
7. Find out the details of top 5 earners of company. (Note: Employee Salaries should not be duplicate like 5k, 4k, 4k, 3k, 2k)
---> select * from (select * from emp order by sal desc) where rownum <= 5;
Output:
| EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO |
| 7839 | king | president | 17-NOV-81 | 6250 | 10 | ||
| 7902 | ford | analyst | 7566 | 03-DEC-81 | 3750 | 20 | |
| 7788 | scott | analyst | 7566 | 09-DEC-82 | 3750 | 20 | |
| 7566 | jones | manager | 7839 | 02-APR-81 | 3718.75 | 20 | |
| 7698 | blake | manager | 7839 | 01-MAY-81 | 3562.5 | 30 |
=============================================================================
8. Display those managers name whose salary is more than an average salary of his employees.
--->select m.ename,m.sal,avg(e.sal) from emp e,emp m where e.mgr=m.empno group by m.ename, m.sal having m.sal>avg(e.sal);
Output:
| ENAME | Sal | AVG(E.Sal) |
| scott | 3750 | 1375 |
| clark | 3062.5 | 1625 |
| king | 6250 | 3447.91667 |
| blake | 3562.5 | 1637.5 |
| ford | 3750 | 1000 |
=============================================================================
9. Display the names of the managers who is having maximum number of employees working under him?
--->select ename from emp where empno in (select mgr from emp group by mgr having count(*)=(select max(count(*)) from emp group by mgr));
Output:
| ENAME |
| blake |
=============================================================================
10. In which year did most people join the company? Display the year and number of employees.
---> select to_char(hiredate,'yyyy') "YEAR",count(EMPNO) "NO. OF Employees" from emp group by to_char(hiredate,'yyyy') having count(empno)=(select max(count(empno)) from emp group by to_char(hiredate,'yyyy'));
Output
| YEAR | NO. OF Employees |
| 1981 | 10 |
=============================================================================
Comments
Post a Comment