爲什麼沒有在甲骨文這個選擇的工作,儘管在PostgreSQL的工作(第三總和應該是在同一個這樣的:從員工選擇SUM(工資)):2表副本從
select e1.employee_id, e1.department_id, e1.manager_id, e1.salary,
sum(e2.salary), sum(e3.salary)
from employees e1, employees e2, employees e3
where e1.department_id=e2.department_id
group by e1.employee_id, e1.department_id, e1.manager_id, e1.salary
order by 1,2;
它的工作原理在PostgreSQL中,但不在這裏。在Oracle工作只有一個副本E2沒有任何約束條件(當e1爲原始表,並通過它的主鍵分組)之後,從:
select e1.employee_id, e1.department_id, e1.manager_id, e1.salary,
sum(e2.salary)
from employees e1, employees e2
where e1.department_id=e2.department_id
group by e1.employee_id, e1.department_id, e1.manager_id, e1.salary
order by 1,2;
或甚至沒有,其中作爲第一表的每個記錄中的整個總和(這裏沒有任何限制):
select e1.employee_id, e1.department_id, e1.manager_id, e1.salary,
sum(e2.salary)
from employees e1, employees e2
group by e1.employee_id, e1.department_id, e1.manager_id, e1.salary
order by 1,2;
當然,我知道其他替代選擇,例如:
select employee_id, department_id, manager_id, salary,
sum(salary) over (partition by department_id) as suma,
sum(salary) over()
from employees order by 2,3;
或與子查詢:
select employee_id, department_id, manager_id, salary,
(select sum(e2.salary) from employees e2
where e2.department_id=e1.department_id) as suma1,
(select sum(e2.salary) from employees e2) as suma2
from employees e1 order by 1,2;
您是否知道在Oracle中執行多個表副本的方法?
*您需要*解釋查詢開始的目的。用簡單的英語。什麼是'sum(e2.salary)'和'sum(e3.salary)'應該達到? –
這是一個學術的例子,他們只是在那裏,有些條件可以是不同的總和,但第三選擇他們只是所有工資的總和。 – 42n4