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 ...
随机推荐
- asp.net 实现 tts
之前用WinForm实现tts已经成功,就调用了下系统的类库.但我把相同的代码搬到asp.net上时却碰到了许多问题,查了好多网站.试过了很多方法,到现在算是做出了一部分吧. 之前调用微软的TTS是用 ...
- Arcgis Engine - 脱离ToolBarControl控件的命令和工具
可以手动实现脱离ToolBarControl控件的命令和工具 //打开文件. private void file_tsmItem_Click(object sender, EventArgs e) { ...
- mvc actionresult 判断是否回发?
if(Request.HttpMethod.Equals("POST", StringComparison.OrdinalIgnoreCase)){POST回发的代码}
- C++访问声明
代码: #include <iostream> #include <string> using namespace std; struct B{ private: int s; ...
- c#鼠标在控件上面,然后显示文字
先添加toolTip控件到界面 然后每个控件的属性会多一项 ToolTip 第一种:直接给里面加文字 第二种: private void pictureBox_topmost_MouseHover(o ...
- DOM之节点|属性
1.查询文档的一个或多个元素有如下方法 a. 用指定的id属性:(若一个文档中有两个相同的id,只会选择第一个;在低于IE8的IE中,getElementById()对匹配元素的ID不区分大小写,而且 ...
- React java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.edaixi.activity/lib-main/libgnustl_shared.so" is 32-bit instead of 64-bit
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.edaixi.activity, PID: 3659 at java.lang.Runtime ...
- EasyShortcut Easyshortcut easyShortcut 简介
关于EasyShortcut Easyshortcut easyShortcut 简介: 参考: http://chunsheng.me/EasyShortcut/
- Python爬虫学习:三、爬虫的基本操作流程
本文是博主原创随笔,转载时请注明出处Maple2cat|Python爬虫学习:三.爬虫的基本操作与流程 一般我们使用Python爬虫都是希望实现一套完整的功能,如下: 1.爬虫目标数据.信息: 2.将 ...
- some logo.
发现一些logo , 储存在这里