Advertisement
Guest User

Untitled

a guest
Jun 12th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 3.08 KB | None | 0 0
  1. --task 2.1st,2.2nd
  2. --select * from emp e join dept d on e.deptno = d.deptno;
  3. --task 2.3rd (select emp name and dname for all employees in alphabetical order)
  4. /*select e.ename, d.dname
  5. from emp e join dept d on e.deptno = d.deptno
  6. order by e.ename asc;*/
  7.  
  8. --task 2.4th (find all employees w/ their numbers and names of deartments they work in)
  9. /*select e.empno, d.dname
  10. from emp e join dept d on d.deptno = e.deptno;*/
  11.  
  12. --task 2.5th(Select employee name, job and department name for all employees who earn more than 1500)
  13. /*select e.ename ,e.job, e.sal, d.dname
  14. from emp e join dept d on e.deptno = d.deptno
  15. where e.sal > 1500;*/
  16.  
  17. --task 2.6th(Get a list of employees with name, job, salary and earning class (table SALGRADE))
  18. /*select e.ename, e.job, e.sal, s.grade
  19. from emp e join salgrade s on e.sal between s.losal and s.hisal;*/
  20.  
  21. -- task 2.7th (Select all information for employees in 3rd earning class)
  22. /*select e.*, s.grade
  23. from emp e join salgrade s on e.sal between s.losal and s.hisal
  24. where s.grade = 3;*/
  25.  
  26. --task 2.8th (Find employees who work in Dallas)
  27.  
  28. /*select e.ename
  29. from emp e join dept d on e.deptno = d.deptno
  30. where d.loc like 'DALLAS';*/
  31.  
  32.  
  33. --task 2.9th (For each employee select his name, department name and earning class)
  34. /*select e.ename, e.deptno, s.grade
  35. from emp e join dept d on e.deptno = d.deptno join salgrade s on e.sal between s.losal and s.hisal;*/
  36.  
  37. --task 2.10th (Find all employees with their numbers and names of departments they work in. Includedepartments without any employees)
  38. /*select e.empno, d.dname
  39. from emp e right join dept d on e.deptno = d.deptno
  40. order by d.dname asc;*/
  41.  
  42. --task 2.12th (Find employees (name, department number) from departments 20 and 30)
  43. /*select e.ename, e.deptno
  44. from emp e join dept d on e.deptno = d.deptno
  45. where d.deptno = 20 or d.deptno = 30
  46. order by d.deptno asc;
  47.  
  48. --task 2.16th (Find employees who earn less than their managers)
  49. /*select e.ename workername, e.sal wsal, m.ename mgrname , m.sal msal
  50. from emp e, emp m
  51. where e.mgr = m.empno and e.sal < m.sal;*/
  52.  
  53. --10. Find all employees with their numbers and names of departments they work in. Include departments without any employees
  54. SELECT e.empno, d.deptno, d.dname FROM emp e right join dept d ON e.deptno = d.deptno;
  55.  
  56. --11. Find all employees with their numbers and names of departments they work in. Include employees without departments
  57. SELECT e.empno, d.deptno, d.dname FROM emp e left join dept d ON e.deptno = d.deptno;
  58.  
  59. --13. List jobs appearing in departments 10 and 30
  60. SELECT e.job FROM emp e WHERE e.deptno = 30
  61. INTERSECT
  62. SELECT e.job FROM emp e WHERE e.deptno = 10;
  63.  
  64. --14.List jobs appearing in department 10 or 30 (or both)
  65. SELECT job FROM emp WHERE deptno = 30
  66. UNION
  67. SELECT job FROM emp WHERE deptno = 10;
  68.  
  69. --15. List jobs appearing in department 10 but not in department 30
  70. SELECT job FROM emp WHERE deptno = 10
  71. MINUS
  72. SELECT job FROM emp WHERE deptno = 30;
  73.  
  74. --17. For each employee show his name and name of the manager. Sort results by managers name
  75. SELECT m.ename, e.ename FROM emp e, emp m WHERE m.empno = e.mgr ORDER BY m.ename;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement