Advertisement
Guest User

Untitled

a guest
Jun 9th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 6.03 KB | None | 0 0
  1. --task 4.1st (Find all employees with salary equal to lowest salary in company)
  2. /*select e.ename from emp e
  3. where e.sal=(select min(e.sal) from emp e);*/
  4.  
  5. --task 4.2nd (Find all employees that have the same job as BLAKE)
  6. /*select e.ename, e.job from emp e
  7. where e.job like (select e.job from emp e where e.ename like 'BLAKE');*/
  8.  
  9. --task 4.3rd (Find all employees with salary equal to lowest salary in each department) ??
  10.  
  11.  
  12. --task 4.4th (Find employees with salary equal to lowest salary in departments they work in)
  13. /*Select e.deptno, e.ename, e.sal from emp e
  14. where e.sal = (select min(sal) from emp e2 where e.deptno = e2.deptno);*/
  15.  
  16. --task 4.5th(Using ANY, find employees with salary greater than lowest salary in department 30)
  17. /*select e.* from emp e
  18. where e.sal > ANY(select min(e2.sal) from emp e2 where e2.deptno =30);*/
  19.  
  20. --task 4.6th(Using ALL, find employees with salary greater than every salary in department 30)
  21. /*select e.* from emp e
  22. where e.sal > ALL(select e2.sal from emp e2 where e2.deptno = 30);*/
  23.  
  24. --task 4.7th(Find employees with salary greater than lowest salary in department 30 (without ANY))
  25. /*select e.ename, e.sal from emp e
  26. where e.sal > (select min(e2.sal) from emp e2 where e2.deptno = 30);*/
  27.  
  28. --task 4.8th(Find employees with salary greater than every salary in department 30 (without ALL))
  29. /*select e.ename, e.sal from emp e
  30. where e.sal > (select max(e2.sal) from emp e2 where e2.deptno = 30);*/
  31.  
  32. --task 4.9th(Find departments with average salary greater than average salary of department 30)
  33. /*select d.deptno, avg(e.sal) from dept d join emp e on d.deptno = e.deptno
  34. group by d.deptno
  35. having avg(e.sal) > (select avg(e2.sal) from emp e2 where e2.deptno = 30);*/
  36. --task 4.10th(Find job with highest average salary)
  37. /*select e.job, avg(e.sal) from emp e
  38. group by e.job
  39. having avg(e.sal) > (select max(avg(e2.sal)) from emp e2 where e2.job != e.job group by e2.job);*/
  40.  
  41. --task 4.11th(Find employees with salary lower than highest salary in SALES (department))
  42. /*select e.* from emp e
  43. where e.sal>ALL(select e2.sal from emp e2 join dept d on e.deptno = d.deptno where d.dname like 'SALES');*/
  44.  
  45. --task 4.12th(Find employees with salary higher than average salary in their departments)
  46. /*select e.* from emp e
  47. where e.sal>(select avg(e2.sal) from emp e2 where e.deptno=e2.deptno);*/
  48.  
  49. --task 4.13th(Using EXISTS, find employees who have subordinates)
  50. /*select e.* from emp e
  51. where EXISTS(select e2.* from emp e2 where e.empno = e2.mgr);*/
  52.  
  53. --task 4.14th(Find employees whose department does not appear in DEPT table) ??
  54.  
  55. -- task 4.15th(For each department find recently hired employees. Sort by hire date)
  56. /*select e.deptno, max(e.hiredate) from emp e
  57. group by e.deptno;*/
  58.  
  59. --task 4.16th(Find departments with no employees (using SUBQUERY))
  60. /*select d.deptno, count(e.empno) from dept d left join emp e on e.deptno = d.deptno
  61. group by d.deptno
  62. having count(e.empno) < ALL(select count(e.empno) from dept d  join emp e on e.deptno = d.deptno
  63. group by d.deptno);*/
  64.  
  65. --task 4.17th(Write a query that returns the percentage share of the number of employees in each department)
  66. /*select e.deptno, round(count(e.empno)/(select count(e2.empno) from emp e2)*100,2) || '%' "% of all employees" from emp e
  67. group by e.deptno;*/
  68.  
  69. --task 5.1st(Find employees who earn the most in their departments)
  70. /*select e.* from emp e where e.sal = (select max(e2.sal) from emp e2 where e2.deptno = e.deptno);*/
  71.  
  72. --task 5.2nd(Find employees who earn above average in their departments)
  73. /*select e.* from emp e where e.sal >(select avg(e2.sal) from emp e2 where e2.deptno = e.deptno);*/
  74.  
  75. --task 5.3rd(Find employees with the lowest earnings in their jobs)
  76. /*select e.* from emp e where e.sal = (select min(e2.sal) from emp e2 where e.job = e2.job);*/
  77.  
  78. --task 5.4th(Find employees who have subordinates using the EXISTS predicate)
  79. /*select e.* from emp e where exists(select e2.* from emp e2 where e2.mgr = e.empno);*/
  80.  
  81. --task 5.5th(Find employees whose department does not appear in the DEPT table)
  82. /*select e.ename, e.deptno from emp e where e.deptno <> ALL(select deptno from dept);*/
  83.  
  84. -- task 5.6th(Using a subquery, find the names and locations of departments without any employees)
  85. /*select d.dname, d.loc from dept d where NOT EXISTS(select e.* from emp e where e.deptno = d.deptno);*/
  86.  
  87. --task 5.7th(Find employees earning the maximum salary in their job positions. Sort results according to decreasing earnings)
  88. /*select e.ename,e.empno, e.sal, e.job from emp e where e.sal = (select min(e2.sal) from emp e2 where e.job = e2.job group by e.job) order by e.sal desc;*/
  89.  
  90. --task 5.8th(Find employees earning a minimum salary in their earning groups. Sort results according to descending earning groups)
  91. /*select e.* from emp e join salgrade s on e.sal between s.losal and s.hisal
  92. where e.sal = (select min(e2.sal) from emp e2 join salgrade s2 on e2.sal between s2.losal and s2.hisal where s.grade = s2.grade group by s2.grade); */
  93.  
  94. --task 5.9th(Identify recently hired employees for each department. Sort results by hire dates)
  95. /*select e.* from emp e join dept d on e.deptno = d.deptno
  96. where to_date(e.hiredate) < to_date(ALL(select min(e2.hiredate) from emp e2 join dept d2 on e2.deptno = d2.deptno where e.empno != e2.empno and e.deptno = e2.deptno group by e2.deptno));*/
  97.  
  98. --task 5.10th(Provide the name, salary and name of the department for employees whose salary exceeds
  99.             --the average of their earning groups.)
  100. /*select e.ename, e.sal, e.deptno from emp e join salgrade s on e.sal between s.losal and s.hisal
  101. where e.sal > (select avg(e2.sal) from emp e2 join salgrade s2 on e2.sal between s2.losal and s2.hisal
  102. where s.grade = s2.grade);*/
  103.  
  104. --task 5.11th(Using a subquery, find employees assigned to non-existent departments)
  105. /*select e.* from emp e where e.deptno != ALL(select d.deptno from dept d);*/
  106.  
  107. --task 5.12th(Indicate the top three earning employees in the company. Show their names and salaries
  108.             --(Assume, that salaries in company are unique))
  109. /*select  e.* from emp e order by e.sal desc fetch first 3 rows only;*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement