天天看点

sum() over

select sum(case job when 'CLERK' then sal end) as cl,
       sum(case job when 'MANAGER' then sal end) as ma from emp;
select sum(decode(job,'CLERK',sal)) as cl,
       sum(decode(job,'MANAGER',sal)) as ma from emp;  --结果同上
select empno,ename,sal,hiredate,sum(sal) over(order by hiredate,sal) from emp ;  --积累
select empno,ename,sal,hiredate,sum(sal) over() from emp ;               --总计  
with sa1 as (select deptno,sum(sal) sss from emp group by deptno order by 1)  
select deptno,sss,ratio_to_report(sss) over() from sa1;              --部门占比
select deptno,ename,sal,ratio_to_report(sal) over() from emp;
select deptno,ename,sal,ratio_to_report(sal) over(partition by deptno) from emp; --员工在部门中的比例