Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. 1) departmanet/job
  2.  
  3. select department_name, job_title, null, max(salary), sum(salary)
  4. from employees e join jobs using (job_id) join departments using (department_id)
  5. group by department_name, job_title
  6.  
  7. union all
  8.  
  9. select null, job_title, e.manager_id, max(salary), sum(salary)
  10. from employees e join jobs using (job_id) join departments using (department_id)
  11. group by job_title,e.manager_id
  12.  
  13. union all
  14.  
  15. select null, null, null, max(salary), sum(salary)
  16. from employees e join jobs using (job_id) join departments using (department_id);
  17.  
  18.  
  19. SELECT department_id, TO_CHAR(hire_date, 'yyyy'), SUM(salary)
  20. FROM employees
  21. WHERE department_id < 50
  22. GROUP BY grouping sets((department_id,TO_CHAR(hire_date, 'yyyy')),(department_id));
  23.  
  24. R C GS
  25. 1) Cate criterii folosesc ptr gen grupuri ? (c1,c2,.....,cn)
  26. toate criterrile posibile(2^n) => cube
  27. n+1 criterii (forma triunghiluara) rollup (intotdeauna primul criteriu e folosit)
  28. GS (G Sets) - definesti tu criterrile definite pt generarea coloanelor
  29. Rollup simulat cu GS
  30. Rollup(c1,c2,c3) => Grouping Sets((c1,c2,c3),(c1,c2),(c1),());
  31.  
  32. select department_name, job_title, e.manager_id, max(salary), sum(salary) ,
  33. grouping(department_name),grouping(job_title),grouping(e.manager_id)
  34. from employees e join jobs using (job_id) join departments using (department_id)
  35. group by grouping sets((department_name, job_title),(job_title,e.manager_id),());
  36.  
  37. select department_name,job_title,avg(salary), count(*)
  38. from employees e full join departments d on(e.department_id = d.department_id)
  39. join jobs j on (e.job_id = j.job_id)
  40. group by cube(department_name,job_title);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement