您的位置:首页 > 数据库 > Oracle

oracle中分析函数

2019-08-12 23:13 260 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/qq_38845271/article/details/99351568

1.1: 字段分区数值汇总

–分析函数 分区
select t.e_no,
t.e_deptno,
t.e_sal,
sum(t.e_sal) over(partition by t.e_deptno) as sumSal, --按部门分区汇总部门员工工资总和不排序
sum(t.e_sal) over(partition by t.e_deptno order by t.e_sal) sumSal2, --按部门分区且排序
sum(t.e_sal) over() sumSal3 --不分区汇总所有工资
from employee t;

1.2 :字段分区后排序
–分析函数 分区排序
select t.e_no,
t.e_deptno,
t.e_sal,
rank() over(partition by t.e_deptno order by t.e_sal) rankSal, --相同e_sal 排名一致且相同的排名一致且 占位
dense_rank() over(partition by t.e_deptno order by t.e_sal) denseSal, --相同e_sal 排名一致 且相同的排名不占位
row_number() over(partition by t.e_deptno order by t.e_sal) rowSal – 相同e_sal 一次排名,不存在并列
from employee t;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: