Eeedi

Bazy danych lab6

May 29th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.74 KB | None | 0 0
  1. SELECT e.LAST_NAME, d.name FROM employee e join  department d ON e.department_id = d.department_id WHERE d.name='RESEARCH' OR d.name='SALES' ORDER BY e.last_name,d.name;
  2.  
  3. SELECT e.last_name, l.regional_group FROM employee e join job j ON j.job_id = e.job_id  join department d ON e.department_id = d.department_id
  4. join location l ON l.location_id = d.location_id WHERE j.FUNCTION='ANALYST' AND (l.regional_group='NEW YORK' OR l.regional_group='BOSTON');
  5.  
  6. SELECT 'Pracownik', e.last_name, 'pracuje na etacie', j.FUNCTION, 'od', e.hire_date FROM employee e join job j ON j.job_id = e.job_id;
  7.  
  8. SELECT e.last_name, d.name, SUM(s.total) FROM employee e join department d ON e.department_id = d.department_id
  9. join job j ON j.job_id = e.job_id
  10. join customer c ON e.employee_id = c.salesperson_id
  11. join sales_order s ON s.customer_id = c.customer_id
  12. WHERE j.FUNCTION='SALESPERSON' AND (s.order_date BETWEEN ADD_MONTHS(TRUNC((SELECT MAX(order_date) FROM sales_order),'mm'),-1) AND LAST_DAY(ADD_MONTHS(TRUNC((SELECT MAX(order_date) FROM sales_order),'mm'),-1)))
  13. GROUP BY e.last_name, d.name;
  14.  
  15. SELECT c.name, SUM(s.total) FROM customer c
  16. full join sales_order s ON s.customer_id = c.customer_id
  17. GROUP BY c.name;
  18.  
  19. SELECT l.regional_group, COUNT(s.total), AVG(s.total) FROM location l
  20. join  department d ON l.location_id = d.location_id
  21. join employee e ON e.department_id = d.department_id
  22. join customer c ON e.employee_id=c.salesperson_id
  23. join sales_order s ON s.customer_id = c.customer_id
  24. WHERE d.name='SALES' GROUP BY l.regional_group;
  25.  
  26. SELECT c.name, s.order_date, i.quantity, p.description FROM customer c
  27. full join sales_order s ON s.customer_id = c.customer_id
  28. full join item i ON s.order_id = i.order_id
  29. full join product p ON p.product_id = i.product_id;
Add Comment
Please, Sign In to add comment