Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. --1
  2. create table employees as select * from HR.EMPLOYEES;
  3. create table departments as select * from HR.DEPARTMENTS;
  4. create table countries as select * from HR.COUNTRIES;
  5. create table jobs as select * from HR.JOBS;
  6. create table locations as select * from HR.LOCATIONS;
  7.  
  8. alter table employees
  9. add primary key (employee_id);
  10.  
  11. alter table jobs
  12. add primary key (job_id);
  13.  
  14. alter table employees
  15. add primary key (employee_id);
  16.  
  17. alter table locations
  18. add primary key (location_id);
  19.  
  20. alter table departments
  21. add primary key (department_id);
  22.  
  23. alter table employees
  24. add foreign key (department_id); reference departments (department_id;)
  25.  
  26. alter table employees
  27. add foreign key (jobs_id); reference jobs (job_id;)
  28.  
  29. alter table locations
  30. add foreign key (department_id); reference locations (location_id;)
  31.  
  32. --2
  33. create view dane60 as select * from employees
  34. where department_id=60;
  35.  
  36. --3
  37. select * from dane60;
  38. update dane60 set salary= salary *1.1;
  39. update dane60 set salary= salary *1.1 where department_id=90;
  40.  
  41. --4
  42. create view DaneShiping as select first_name, last_name, salary
  43. from employees join departments using (department_id)
  44. where department_name= 'Shipping';
  45. --5
  46. create view danePracow as select first_name, last_name, nvl2(commision_pct,(commision_pct+1)*salary*12,salary*12)
  47. as wynagrodzenie
  48. from employees;
  49. --6
  50. drop view
  51.  
  52.  
  53.  
  54.  
  55.  
  56. --7
  57. create view dane as select employee_id, first_name, last_name, job_title
  58. from employees join jobs using (job_id);
  59. select * from danePrac;
  60. update danePrac set first_name = 'Jan' where employee_id=206;
  61. drop view danePrac;
  62. create view dane as select employee_id, first_name, last_name, job_title
  63. from employees join jobs using (job_id);
  64. with read only;
  65.  
  66. --8
  67.  
  68. create view stanowiska as select job_id, count(employee_id) as liczba
  69. from employees
  70. group by job_id;
  71.  
  72. --9
  73.  
  74. create view oddzial as select count(employee_id) as liczbapracow, min(salary) as minimalna, max(salary) as maxymalna
  75. from employees;
  76. group by department_id;
  77.  
  78. --10
  79. create view liczbaOddzialow as select country_name, count(department_id) as liczbaOddz, count(employee_id) as liczbaprac
  80. from employees join departments usig (department_id)
  81. join locations using (location_id)
  82. join counties using (country_id)
  83. group by country_name;
  84.  
  85. select * from liczbaOddzialow
  86. frop view liczbaOddzialow;
  87.  
  88. --11
  89.  
  90. create or replace view Pensje as select department_name, min(salary) as minimalna, max(salary) as maksymalna
  91. avg(salary) as srednia
  92. from employees join departments using (department_id)
  93. group by department_name;
  94. select * from Pensje;
  95. update Pensje set department_name = 'New IT' from department_name = 'IT';
  96.  
  97. --12
  98.  
  99. create view danePracow as select first_name,last_name,job_title
  100. from employees join jobs using (job_id)
  101. group by job_title;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement