Oracle:grouping和rollup
Oracle grouping和rollup简单测试
SQL> select department_id,sum(salary) from employees where department_id in(10,30,90,100) group by department_id order by department_id;
DEPARTMENT_ID SUM(SALARY)
------------- -----------
10 4400
30 24900
90 58000
100 51608 SQL> select department_id,first_name,sum(salary) from employees where department_id in(10,30,90,100) group by (department_id,first_name) order by department_id;
DEPARTMENT_ID FIRST_NAME SUM(SALARY)
------------- -------------------- -----------
10 Jennifer 4400
30 Alexander 3100
30 Den 11000
30 Guy 2600
30 Karen 2500
30 Shelli 2900
30 Sigal 2800
90 Lex 17000
90 Neena 17000
90 Steven 24000
100 Daniel 9000
100 Ismael 7700
100 John 8200
100 Jose Manuel 7800
100 Luis 6900
100 Nancy 12008
16 rows selected SQL> select department_id,first_name,sum(salary) from employees where department_id in(10,30,90,100) group by rollup(department_id,first_name) order by department_id;
DEPARTMENT_ID FIRST_NAME SUM(SALARY)
------------- -------------------- -----------
10 Jennifer 4400
10 4400
30 Alexander 3100
30 Den 11000
30 Guy 2600
30 Karen 2500
30 Shelli 2900
30 Sigal 2800
30 24900
90 Lex 17000
90 Neena 17000
90 Steven 24000
90 58000
100 Daniel 9000
100 Ismael 7700
100 John 8200
100 Jose Manuel 7800
100 Luis 6900
100 Nancy 12008
100 51608
DEPARTMENT_ID FIRST_NAME SUM(SALARY)
------------- -------------------- -----------
138908
21 rows selected SQL> select department_id,grouping(department_id),first_name,grouping(first_name),sum(salary) from employees where department_id in(10,30,90,100) group by rollup(department_id,first_name) order by department_id;
DEPARTMENT_ID GROUPING(DEPARTMENT_ID) FIRST_NAME GROUPING(FIRST_NAME) SUM(SALARY)
------------- ----------------------- -------------------- -------------------- -----------
10 0 Jennifer 0 4400
10 0 1 4400
30 0 Alexander 0 3100
30 0 Den 0 11000
30 0 Guy 0 2600
30 0 Karen 0 2500
30 0 Shelli 0 2900
30 0 Sigal 0 2800
30 0 1 24900
90 0 Lex 0 17000
90 0 Neena 0 17000
90 0 Steven 0 24000
90 0 1 58000
100 0 Daniel 0 9000
100 0 Ismael 0 7700
100 0 John 0 8200
100 0 Jose Manuel 0 7800
100 0 Luis 0 6900
100 0 Nancy 0 12008
100 0 1 51608
DEPARTMENT_ID GROUPING(DEPARTMENT_ID) FIRST_NAME GROUPING(FIRST_NAME) SUM(SALARY)
------------- ----------------------- -------------------- -------------------- -----------
1 1 138908
21 rows selected
rollup为按分组统计小计和。
grouping(department_id)和grouping(first_name)
如果当前列所在的行为空,则显示为1,不为空则显示为0;
Oracle:grouping和rollup的更多相关文章
- Oracle分析函数 — sum, rollup, cube, grouping用法
本文通过例子展示sum, rollup, cube, grouping的用法. //首先建score表 create table score( class nvarchar2(20), course ...
- SQL GROUP BY GROUPING SETS,ROLLUP,CUBE(需求举例)
实现按照不同级别分组统计 关于GROUP BY 中的GROUPING SETS,ROLLUP,CUBE 从需求的角度理解会更加容易些. 需求举例: 假如一所学校只有两个系, 每个系有两个专业, 每个专 ...
- oracle group by rollup,decode,grouping,nvl,nvl2,nullif,grouping_id,group_id,grouping sets,RATIO_TO
干oracle 047文章12当问题,经验group by 声明.因此邂逅group by rollup,decode,grouping,nvl,nvl2,nullif,RATIO_TO_REPOR ...
- Oracle Group by+rollup+cube 的应用
首先我们创建一个示例表: Create table test_group (v_name varchar2(4) ,v_size varchar2(4) ,v_color varchar2(4) ,n ...
- 【Teradata】grouping和rollup窗口函数
1.group by后带rollup子句 先按一定的规则产生多种分组,然后返回各个分组所产生的结果集的并集,且没有去掉重复数据(统计出的数据是求和还是最大值还是平均值等这就取决于SELECT后的聚合函 ...
- Hive高级聚合GROUPING SETS,ROLLUP以及CUBE
scala> import org.apache.spark.sql.hive.HiveContextimport org.apache.spark.sql.hive.HiveContext s ...
- (2.4)DDL增强功能-数据汇总grouping、rollup、cube
参考:https://www.cnblogs.com/nikyxxx/archive/2012/11/27/2791001.html 1.rollup (1)rollup在group by 子句中使用 ...
- MS SQL 分类汇总参数 grouping(**)=1 rollup cubt
转:http://www.111cn.net/database/mssqlserver/43368.htm 本文章介绍了关于sql多级分类汇总实现方法及数据结构,有碰到问题的同学可参考一下. 据库结构 ...
- oracle GROUP BY rollup
1.ROW_NUMBER() OVER函数的基本用法用法 http://www.cnblogs.com/fxgachiever/archive/2010/09/15/1826792.html 2.De ...
随机推荐
- javascript之求最值
求最值: var selections = $("#deliveryGridSalesOrGoods").datagrid('getRows'); var costPrice = ...
- Sass函数--颜色函数--Opacity函数
Opacity函数简介 在 CSS 中除了可以使用 rgba.hsla 和 transform 来控制颜色透明度之外,还可以使用 opacity 来控制,只不过前两者只是针对颜色上的透明通道做处理,而 ...
- MVC5富文本编辑器CKEditor配置CKFinder
富文本编辑器CKEditor的使用 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...
- 在CentoOS中安装g++ 并连接Oracle数据库
1.安装运行环境 # yum install gcc-c++ 备注:此时会将gcc-c++和libstdc++-devel都安装上. 2.查看g++是否安装成功[root@MyRHEL 桌面]# g+ ...
- C#远程获取/读取网页内容
转载自 :http://blog.csdn.net/gisfarmer/article/details/2836904 using System; using System.Collections.G ...
- IP地址变动后,https://localhost:1158/em无法访问解决办法
一.解决的方法:重新配置em 二.步骤: 1.在 dos命令下输入 emca –repos drop 注意:监听端口号是一般是1521,特殊情况要在配置文件中找 2.成功删除资料档案库后,在dos下再 ...
- struts 2 --SEVERE: Could not find action or result
SEVERE: Could not find action or result There is no Action mapped for namespace / and action name . ...
- webrtc之视频显示模块--video_render
在上一篇博文中,简单介绍了webrtc为我们提供了跨平台的视频采集模块,这篇博文也简单介绍下webrtc为我们提供的跨平台的视频显示模块:video_render. 该模块的源码结构如下: 如上图,我 ...
- C++新式类型转换
C++的四种强制类型转换,所以C++不是类型安全的.分别为:static_cast , dynamic_cast , const_cast , reinterpret_cast 新类型的强制转换可以提 ...
- python之pandas模块
一.pandas模块是基于Numpy模块的,pandas的主要数据结构是Series和DadaFrame,下面引入这样的约定: from pandas import Series,DataFrame ...