Oracle之group by 扩展分组函数测试学习过程如下:-
--rollup:以每个部门为参考对象,每个部门下员工薪水的明细和汇总
select t.dept_id,t.dept_name,sum(t.salary)
from qcfang.test1 t
group by rollup(t.dept_id,t.dept_name)
--cube:信息量最大的交叉报表,汇总,明细均有
select t.dept_id,t.dept_name,sum(t.salary)
from qcfang.test1 t
group by cube(t.dept_id,t.dept_name)
--rollup 取消最后的总计,其实是过滤掉了dept_id 为null的记录
select t.dept_id,t.dept_name,sum(t.salary)
from qcfang.test1 t
group by t.dept_id, rollup(t.dept_name)
order by t.dept_id
--cube取消总计,其实是过滤掉了dept_id为null的记录
select t.dept_id,t.dept_name,sum(t.salary)
from qcfang.test1 t
group by t.dept_id,cube(t.dept_name)
--grouping settings:每个维度不同值的汇总,相当于多个union all
select t.dept_id,t.dept_name,sum(t.salary)
from qcfang.test1 t
group by grouping sets(t.dept_id,t.dept_name)
--利用grouping 函数,找出哪些是合计:flag=1为合计.
select t.dept_id,t.dept_name,sum(t.salary),grouping(t.dept_name)flag
from qcfang.test1 t
group by rollup(t.dept_id,t.dept_name)
order by t.dept_id
--利用grouping函数过滤分组
select t.dept_id,t.dept_name,sum(t.salary),grouping(t.dept_name)flag
from qcfang.test1 t
group by rollup(t.dept_id,t.dept_name)
having grouping(t.dept_name) =0
--利用grouping_id 进行排序
select t.dept_id,t.dept_name,sum(t.salary),grouping(t.dept_name)flag
from qcfang.test1 t
group by rollup(t.dept_id,t.dept_name)
order by grouping_id(t.dept_id,t.dept_name),t.dept_id推荐阅读:Oracle的Lpad函数 http://www.linuxidc.com/Linux/2013-11/92828.htmOracle正则表达式函数详解 http://www.linuxidc.com/Linux/2013-11/92229.htmOracle DB 组函数 http://www.linuxidc.com/Linux/2013-10/91663.htmOracle DB 使用转换函数和条件表达式 http://www.linuxidc.com/Linux/2013-10/91662.htmOracle中窗口函数over()的学习 http://www.linuxidc.com/Linux/2013-08/89405.htm更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12ASM磁盘创建提示“Marking disk “VOL1” as an ASM disk: [FAILED]”Oracle之sqlplus / as sysdba;相关资讯 Oracle函数 Oracle分组函数 Group by
- Oracle字符串函数总结 (06月20日)
- MySQL 5.7与5.6 group by的不同之 (01月09日)
- Oracle lag()与lead() 函数 (12/01/2015 20:41:24)
| - Oracle使用简单函数 (06月09日)
- MySQL有关Group By的优化 (12/12/2015 13:49:53)
- REGEXP_SUBSTR函数的整理 (08/20/2015 20:41:01)
|
本文评论 查看全部评论 (0)