Guest User

13123213213213

a guest
Jan 3rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. -- zad1
  2. create table employees1 as
  3. select * from hr.employees;
  4. create table departaments1 as
  5. select * from hr.departaments;
  6. create table jobs1 as
  7. select * from hr.jobs;
  8. create table locations1 as
  9. select * from hr.locations;
  10.  
  11. alter table employees1 add primary key (employee_id);
  12. alter table departaments add primary key (departament_id);
  13. alter table jobs1 add primary key (job_id);
  14. alter table locations1 add primary key (locations_id);
  15.  
  16. select * from departaments;
  17.  
  18. -- zad 2
  19. create view v_emplyees60 as
  20. select * from employees1 where departament_id=60;
  21.  
  22.  
  23.  
  24. -- zad 3
  25. select * from v_employees60;
  26. update v_employees1 set salary =1.1*salary where departament_id=60;
  27. update employee60 set salary=1.1*salary where departament_id=90;
  28.  
  29. --zad 4
  30. create or replace view v_imiona as
  31. select first_name, last_name, salary
  32. from employees1 join departaments1 using(departament_id)
  33. where job_title like 'Shipping';
  34.  
  35. select * from v_imiona;
  36.  
  37. -- zad 5
  38. create view v_elo as
  39. select first_name, last_name, 12*salary as "roczna"
  40. from employes1;
  41.  
  42. select * from v_elo;
  43.  
  44. --zad6
  45. drop view v_elo;
  46.  
  47. -- zad7
  48. create view v_prac as
  49. select employee_id, first_name, job_title
  50. from employees1 join jobs1 using (job_id);
  51.  
  52. select * from v_prac;
  53.  
  54. update v_prac set first_name = 'jakub' where first_name='William';
  55.  
  56. select * from v_prac;
  57.  
  58.  
  59. create or replace view v_prac as
  60. select employee_id, first_name, job_title
  61. from employees1 join jobs1 using (job_id)
  62. with read only;
  63.  
  64.  
  65. update v_prac set first_name = 'jakub' where first_name='William';
  66.  
  67. select * from v_prac;,
  68.  
  69. -- zad8
  70. create view v_id as
  71. select job_title, count(employee_id) as "liczba pracownikow"
  72. from employees1 join jobs1 using (job_id)
  73. group by jobs1.job_title;
  74.  
  75. select * from v_id;
  76.  
  77. -- zad 9
  78. create view v_oddzial as
  79. select departament_name, count(employee_id) as ilosc, max(salary)
  80. as "maksymalna pensja", min(salary) as "minimalna pensja" from
  81. from departaments1 join employees1 using (departament_id)
  82. group by departament_name;
  83.  
  84. select * from v_oddzial;
  85.  
  86. -- zad 10
  87. create view v_panstwa as
  88. select country_id, count(departament_id) as "liczba oddzialow",
  89. count(employee_id) as "liczba pracownikow"
  90. from employees1 join departments1 using(departament_id)
  91. join location1 using(location_id) group by country_id;
  92.  
  93. select * from v_panstwa;
  94.  
  95. --zad11
  96. create or replace view oddzial_pensja as
  97. select min(salary) as "minimalna", max (salary) as "maksymalna" ,
  98. avg(salary) as "srednia" from employees1 join departaments1 using(departament_id)
  99. group by departament_name;
  100.  
  101. select * from oddzial_pensja;
  102.  
  103. update oddzial_pensja set departament_name = 'new it' where departament_name = 'it';
  104.  
  105.  
  106. -- zad 12
  107. create view v_pracownik2 as
  108. select first_name, last_name, job_title
  109. from emploees1 join jobs1 using (job_id);
  110.  
  111. insert into v_pracownik2 (first_name, last_name, job_title)
  112. values ('jakub','jakubiak', '123');
  113.  
  114. update v_pracownik set first_name = 'kuba' where first_name = 'jakub'
  115. delete from v_pracownik2 where first_name ='kuba';
  116.  
  117. select *from v_pracownik2;
  118.  
  119. -- zad13
  120. create view v_prac_zarob as select first_name, last_name, salary
  121. from employees where salary<7000 order by salary asc;
  122. select * from v_prac_zarob;
  123.  
  124. update v_prac_zarob set salary=8000 where first_name='jan';
  125.  
  126. --zad 14
  127. create or replace view v_prac_zarob as select first_name, last_name, salary
  128. from employees where salary<7000 order by salary asc
  129. with check option;
  130.  
  131. update v_prac_zarob set salary=8000 where first_name='steven';
  132.  
  133. select * from v_prac_zarob;
Advertisement
Add Comment
Please, Sign In to add comment