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的更多相关文章

  1. Oracle分析函数 — sum, rollup, cube, grouping用法

    本文通过例子展示sum, rollup, cube, grouping的用法. //首先建score表 create table score( class  nvarchar2(20), course ...

  2. SQL GROUP BY GROUPING SETS,ROLLUP,CUBE(需求举例)

    实现按照不同级别分组统计 关于GROUP BY 中的GROUPING SETS,ROLLUP,CUBE 从需求的角度理解会更加容易些. 需求举例: 假如一所学校只有两个系, 每个系有两个专业, 每个专 ...

  3. 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 ...

  4. Oracle Group by+rollup+cube 的应用

    首先我们创建一个示例表: Create table test_group (v_name varchar2(4) ,v_size varchar2(4) ,v_color varchar2(4) ,n ...

  5. 【Teradata】grouping和rollup窗口函数

    1.group by后带rollup子句 先按一定的规则产生多种分组,然后返回各个分组所产生的结果集的并集,且没有去掉重复数据(统计出的数据是求和还是最大值还是平均值等这就取决于SELECT后的聚合函 ...

  6. Hive高级聚合GROUPING SETS,ROLLUP以及CUBE

    scala> import org.apache.spark.sql.hive.HiveContextimport org.apache.spark.sql.hive.HiveContext s ...

  7. (2.4)DDL增强功能-数据汇总grouping、rollup、cube

    参考:https://www.cnblogs.com/nikyxxx/archive/2012/11/27/2791001.html 1.rollup (1)rollup在group by 子句中使用 ...

  8. MS SQL 分类汇总参数 grouping(**)=1 rollup cubt

    转:http://www.111cn.net/database/mssqlserver/43368.htm 本文章介绍了关于sql多级分类汇总实现方法及数据结构,有碰到问题的同学可参考一下. 据库结构 ...

  9. oracle GROUP BY rollup

    1.ROW_NUMBER() OVER函数的基本用法用法 http://www.cnblogs.com/fxgachiever/archive/2010/09/15/1826792.html 2.De ...

随机推荐

  1. Web App 前端构建(纯净版)

    asp.net 母版页: <!DOCTYPE html> <html> <head> <meta charset="utf-8" name ...

  2. [Asp.Net]状态管理(Session、Application、Cache、Cookie 、Viewstate、隐藏域 、查询字符串)

    Session:  1. 客户在服务器上第一次打开Asp.Net页面时,会话就开始了.当客户在20分钟之内没有访问服务器,会话结束,销毁session.(当然也可以在Web.config中设置缓存时间 ...

  3. (转)web.config详解之在文件中配置网站默认页面

    在<configuration></configuration>中添加下面的配置 <system.webServer>        <defaultDocu ...

  4. PHP 日期格式化 参数参考

    a - "am" 或是 "pm" A - "AM" 或是 "PM" d - 几日,二位数字,若不足二位则前面补零; 如: ...

  5. CAS单点登录原理以及debug跟踪登录流程

    CAS 原理和协议 基础模式 基础模式 SSO 访问流程主要有以下步骤: 1. 访问服务: SSO 客户端发送请求访问应用系统提供的服务资源. 2. 定向认证: SSO 客户端会重定向用户请求到 SS ...

  6. MFC的初始化过程和消息映射技术

    1.删除#include <windows.h>--win32中的-(使用win32工程编程mfc必须删除) 添加#include <afxwin.h> -- mfc中的- 2 ...

  7. 在java中生成二维码,并直接输出到jsp页面

    在java中生成的二维码不存到磁盘里要直接输出到页面上,这就需要把生成的二维码直接以流的形式输出到页面上,我用的是myeclipse 和 tomcat 它的原理是:在加载页面时,根据img的src(c ...

  8. 关于Repeater中绑定的控件不触发ItemCommand事件

    今天遇到 在repeater 中使用一个button,点击button然后跳转另外一个页面. html. <asp:Repeater ID="repeater" runat= ...

  9. httpcomponents-client-4.3.6 HttpPost的简单使用

    /** * httpcomponents-client-4.3.6 * @author y */ public class HttpUtil { public static String httpPo ...

  10. android获取sdk更新

    http://www.th7.cn/Program/Android/201310/154981.shtml 网上许多解决 Android SDK Manager 无法更新(下载)的问题的方法基本都是将 ...