–求和两种结果相同
select e.employee_id ,e.first_name,e.salary,sum(e.salary)
from employees e
group by e.employee_id ,e.first_name,e.salary;
select e.employee_id ,e.first_name,e.salary,sum(e.salary) over() sum
from employees e;
–求和
–第二行的sum=第一行里的sal+第二行里的sal;
— 第二行的sum=第一行里的sal+第二行里的sal+第三行里的sal;
select e.employee_id,
e.department_id,
e.first_name,
e.salary,
sum(e.salary) over(order by e.first_name) sum
from employees e;
–每个sum的值都是把last_name相同的sal值进行求和。
select e.employee_id,
e.department_id,
e.last_name,
e.salary,
sum(e.salary) over(partition by e.last_name) sum
from employees e;