ORACLE分析函数的应用例子1 over partition by
2008-08-20 21:19
519 查看
用分析函数来得出的的工资 占 部门比 工资占 公司 比
--包括工名,部门 工资 需要得出部门工资的总数,某员工的工资 占所在部门总工资数的百分比,以及占总工资数的百分比
select deptno,
ename,
sal,
sum(sal) over(partition by deptno order by sal, ename) cum_sal,
round(100 * ratio_to_report(sal) over(partition by deptno), 1) pct_dept,
round(100 * ratio_to_report(sal) over(), 1) pct_overall
from emp
order by deptno, sal;
通用的程序ORACLE 9 以下数据库都可以用的
select emp.deptno,
emp.ename,
emp.sal,
sum(emp4.sal) cum_sal,
round(100 * emp.sal / emp2.sal_by_dept, 1) pct_dept,
round(100 * emp.sal / emp3.sal_overall, 1) pct_overall
from emp,
(select deptno, sum(sal) sal_by_dept from emp group by deptno) emp2,
(select sum(sal) sal_overall from emp) emp3,
emp emp4
where emp.deptno = emp2.deptno
and emp.deptno = emp4.deptno
and (emp.sal > emp4.sal or
(emp.sal = emp4.sal and emp.ename >= emp4.ename))
group by emp.deptno,
emp.ename,
emp.sal,
round(100 * emp.sal / emp2.sal_by_dept, 1),
round(100 * emp.sal / emp3.sal_overall, 1)
order by deptno, sal;
但是使用 分析函数 数据执行速度比较块 而且随着数据增多 速度成数量级别递增
--包括工名,部门 工资 需要得出部门工资的总数,某员工的工资 占所在部门总工资数的百分比,以及占总工资数的百分比
select deptno,
ename,
sal,
sum(sal) over(partition by deptno order by sal, ename) cum_sal,
round(100 * ratio_to_report(sal) over(partition by deptno), 1) pct_dept,
round(100 * ratio_to_report(sal) over(), 1) pct_overall
from emp
order by deptno, sal;
通用的程序ORACLE 9 以下数据库都可以用的
select emp.deptno,
emp.ename,
emp.sal,
sum(emp4.sal) cum_sal,
round(100 * emp.sal / emp2.sal_by_dept, 1) pct_dept,
round(100 * emp.sal / emp3.sal_overall, 1) pct_overall
from emp,
(select deptno, sum(sal) sal_by_dept from emp group by deptno) emp2,
(select sum(sal) sal_overall from emp) emp3,
emp emp4
where emp.deptno = emp2.deptno
and emp.deptno = emp4.deptno
and (emp.sal > emp4.sal or
(emp.sal = emp4.sal and emp.ename >= emp4.ename))
group by emp.deptno,
emp.ename,
emp.sal,
round(100 * emp.sal / emp2.sal_by_dept, 1),
round(100 * emp.sal / emp3.sal_overall, 1)
order by deptno, sal;
但是使用 分析函数 数据执行速度比较块 而且随着数据增多 速度成数量级别递增
相关文章推荐
- sql实现oracle分析函数功能 over partition by
- oracle分析函数sum/ration_to_report(column) over (partition by column order by column)
- oracle的“over partition by”的用法,over不能单独使用,要和分析函数:rank(),dense_rank(),row_number()等一起使用。
- Oracle分析函数中的分组排名函数用法 Rank Over partition by
- oracle 分析函数:ROW_NUMBER() OVER(PARTITION BY ID ORDER BY VERSION DESC)
- Oracle 分析函数row_number() over (partition by order by ) 的 Mysql的替代方法
- oracle分析函数over partition by 和group by的区别
- 【Oracle】row_number() over(partition by )函数用法
- Oracle分析函数 OVER(PARTITION ORDER WINDOWING)(四)—— 多维度分组统计函数用法
- oracle over(partition BY) 函数用法
- 分析函数入门sum...over(partition by xxx order by yyy rows between zzz)
- Oracle分析函数 OVER(PARTITION ORDER WINDOWING)(二)—— 类聚合函数用法
- Oracle分析函数 OVER(PARTITION ORDER WINDOWING)(三)—— 排序顺序相关函数用法
- OVER(PARTITION BY)函数用法 oracle
- oracle下的OVER(PARTITION BY)函数介绍
- SQL中分析函数ROW_NUMBER() OVER(PARTITION BY GRADEOBJECTID ORDER BY BG.GRADEDATE DESC)的用法!!!
- Oracle分析函数 OVER(PARTITION ORDER WINDOWING)(一)—— 函数列表
- Oracle OVER(PARTITION BY)函数
- Oracle之row_number() / rank() / dense_rank() / over(partition order by)序列函数
- ORACLE 的OVER(PARTITION BY... ORDER BY...)分析函数讲解