正确答案:C

在Oracle 8i中引入GROUPING(<列引用>)函数,被用来做为GROUPING()函数参数的表达式必须与出现在GROUP BY 子句中的表达式相匹配。包含了CUBE、ROLLUP或GROUPING SET关键字的组查询时,该函数对<列引用>相关列的聚合结果中的NULL值进行检查。例如通过写出decode(grouping(id),1,’ALLID’,id) id来检测id是否有一行由CUBE产生的空值,或着是否其在数据库中本身就是空值。如果这些NULL值是由本次CUBE查询生成的,那么返回,否则返回0。

官方解释:GROUPING distinguishes superaggregate rows fromregular grouped rows. GROUP BY extensions such as ROLLUP and CUBE produce superaggregate rows where the set of all values is represented bynull. Using the GROUPING function,you can distinguish a null representing the set of all values in asuperaggregate row from a null in a regular row.

The expr in the GROUPING function must matchone of the expressions in the GROUP BY clause. The functionreturns a value of 1 if the value ofexpr in the row is a nullrepresenting the set of all values. Otherwise, it returns zero. The datatype ofthe value returned by the GROUPING function is Oracle NUMBER. Please refer to theSELECTgroup_by_clause for a discussion of theseterms.

Examples 1

In the following example, which uses the sample tables hr.departments andhr.employees, if the GROUPING function returns 1 (indicating asuperaggregate row rather than a regular row from the table), then the string"All Jobs" appears in the "JOB" column instead of the nullthat would otherwise appear:

SQL> SELECT DECODE(GROUPING(department_name), 1, 'All Departments',
2 department_name) AS department,
3 DECODE(GROUPING(job_id), 1, 'All Jobs', job_id) AS job,
4 COUNT(*) "Total Empl", AVG(salary) * 12 "Average Sal"
5 FROM employees e, departments d
6 WHERE d.department_id = e.department_id
7 GROUP BY ROLLUP (department_name, job_id); DEPARTMENT JOB Total Empl Average Sal
------------------------------ ---------- ---------- -----------
IT IT_PROG 5 69120
IT All Jobs 5 69120
Sales SA_MAN 5 146400
Sales SA_REP 29 100758.621
Sales All Jobs 34 107470.588
Finance FI_MGR 1 144096
Finance FI_ACCOUNT 5 95040
Finance All Jobs 6 103216
Shipping ST_MAN 5 87360
Shipping SH_CLERK 20 38580
Shipping ST_CLERK 20 33420 DEPARTMENT JOB Total Empl Average Sal
------------------------------ ---------- ---------- -----------
Shipping All Jobs 45 41706.6667
Executive AD_VP 2 204000
Executive AD_PRES 1 288000
Executive All Jobs 3 232000
Marketing MK_MAN 1 156000
Marketing MK_REP 1 72000
Marketing All Jobs 2 114000
Accounting AC_MGR 1 144096
Accounting AC_ACCOUNT 1 99600
Accounting All Jobs 2 121848
Purchasing PU_MAN 1 132000 DEPARTMENT JOB Total Empl Average Sal
------------------------------ ---------- ---------- -----------
Purchasing PU_CLERK 5 33360
Purchasing All Jobs 6 49800
Administration AD_ASST 1 52800
Administration All Jobs 1 52800
Human Resources HR_REP 1 78000
Human Resources All Jobs 1 78000
Public Relations PR_REP 1 120000
Public Relations All Jobs 1 120000
All Departments All Jobs 106 77481.0566 31 rows selected.

Examples 2

SQL> create table gyj_test(id int,name varchar2(10));

Table created.
SQL> insert into gyj_test values(1,'A'); 1 row created. SQL> insert into gyj_test values(1,'A'); 1 row created. SQL> insert into gyj_test values(1,'A'); 1 row created. SQL> insert into gyj_test values(2,'B'); 1 row created. SQL> insert into gyj_test values(2,'B'); 1 row created. SQL> insert into gyj_test values(3,'C'); 1 row created. SQL> commit; Commit complete. SQL> select id,name,sum(id) sumid,grouping(id),grouping(name) from gyj_test group by rollup(id,name); ID NAME SUMID GROUPING(ID) GROUPING(NAME)
---------- ---------- ---------- ------------ --------------
1 A 3 0 0
1 3 0 1
2 B 4 0 0
2 4 0 1
3 C 3 0 0
3 3 0 1
10 1 1 7 rows selected.

[每日一题] OCP1z0-047 :2013-08-15 描述GROUPING 函数 .......................................43的更多相关文章

  1. [每日一题] OCP1z0-047 :2013-08-06 外表部――相关描述

    这道题目的知识点是要你熟悉外部表,怎么建外部表,外部表的数据是怎么存储的等等.请给出正确答案,并解释A B C D每项,最好用实验测试证明! 外部表的metadata(元数据)是存在数据库中,但它的数 ...

  2. [每日一题] OCP1z0-047 :2013-08-12 view视图的描述哪些是正确的?

    正确答案是: CE 这是OCP教材中的: 1.简单视图与复杂视图的定义: 2.复杂视图通常不能被DML: .WITH CHECKOP TIONT选项 A不正确.简单视图可以被更新. hr@OCM> ...

  3. 【js】Leetcode每日一题-数组异或操作

    [js]Leetcode每日一题-数组异或操作 [题目描述] 给你两个整数,n 和 start . 数组 nums 定义为:nums[i] = start + 2*i(下标从 0 开始)且 n == ...

  4. 【JavaScript】Leetcode每日一题-平方数之和

    [JavaScript]Leetcode每日一题-平方数之和 [题目描述] 给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c . 示例1: 输入:c = 5 ...

  5. 【JavaScript】Leetcode每日一题-递增顺序搜索树

    [JavaScript]Leetcode每日一题-递增顺序搜索树 [题目描述] 给你一棵二叉搜索树,请你 按中序遍历 将其重新排列为一棵递增顺序搜索树,使树中最左边的节点成为树的根节点,并且每个节点没 ...

  6. 【JavaScript】Leetcode每日一题-组合总和4

    [JavaScript]Leetcode每日一题-组合总和4 [题目描述] 给你一个由 不同 整数组成的数组 nums ,和一个目标整数 target .请你从 nums 中找出并返回总和为 targ ...

  7. 【JavaScript】Leetcode每日一题-最大整除子集

    [JavaScript]Leetcode每日一题-最大整除子集 [题目描述] 给你一个由 无重复 正整数组成的集合 nums ,请你找出并返回其中最大的整除子集 answer ,子集中每一元素对(an ...

  8. 【JavaScript】Leetcode每日一题-移除元素

    [JavaScript]Leetcode每日一题-移除元素 [题目描述] 给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度. 不要使用 ...

  9. 【python】Leetcode每日一题-丑数2

    [python]Leetcode每日一题-丑数2 [题目描述] 给你一个整数 n ,请你找出并返回第 n 个 丑数 . 丑数 就是只包含质因数 2.3 和/或 5 的正整数. 示例1: 输入:n = ...

随机推荐

  1. 《CSS网站布局实录》学习笔记(二)

    第二章 XHTML与CSS基础 2.1 XHTML基础 XHTML是网页代码的核心内容,标准XHTML代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD ...

  2. 解决:debug-stripped.ap_' specified for property 'resourceFile' does not exist.

    1.错误描述 更新Android Studio到2.0版本后,出现了编译失败的问题,我clean project然后重新编译还是出现抑郁的问题,问题具体描述如下所示: Error:A problem ...

  3. IOS创建开源库步骤,提交cocoa pods官网,别人可以使用

    1.打开终端进入某个目录执行  pod lib create BMBlinkButton,按命令步骤执行. 2.目录结构 3.修改BMBlinkButton.podspec文件 4.进入Example ...

  4. 如何安装Git到MAC OS X

    这里介绍两种方式:一,使用Git command-line二,使用GUI工具SourceTree,功能很强大,很方便 在进行安装前,要说一下,Git和SVN一样,都需要创建一个服务器的,他们都可以创建 ...

  5. 跟踪对象属性值的修改, 设置断点(Break on property change)

    代码 //Break on property change (function () { var localValue; Object.defineProperty(targetObject, 'pr ...

  6. 直接拨号、将电话号码传入拨号程序、调用拨号程序、调用系统浏览器浏览网页、调用系统程序查看联系人、显示系统设置界面和显示Wi-Fi设置界面代码

    直接拨号.将电话号码传入拨号程序.调用拨号程序.调用系统浏览器浏览网页.调用系统程序查看联系人.显示系统设置界面和显示Wi-Fi设置界面代码 拨打号码的代码如下: Intent callIntent= ...

  7. [转载] 与WIN不同,linux替换文件夹会删除原文件夹下的全部内容!

    今天差点把源码给覆盖掉了><...555... 虚惊一场!!看了一篇博客分析这种情况.我的环境是CentOS5.5,不会出现文件夹直接被覆盖的情况,但是在Linux下不要用Win下的一些直 ...

  8. 在线支付接口之PHP支付宝接口开发

    支付接口一般是第三方提供的代收款.付款的平台,可以通过支付接口帮助企业或个人利用一切可以使用的支付方式.常见支付平台:支付宝.快钱.云网支付.财付通. 支付宝页面:订单页面.状态页面.返回页面.--- ...

  9. innerHTML的运用

    <!doctype html> <html> <style> li{float:left;margin:0 100px;color:red;} </style ...

  10. C#中的委托和事件2-2(转)

    引言 如果你看过了 C#中的委托和事件2-1 一文,我想你对委托和事件已经有了一个基本的认识.但那些远不是委托和事件的全部内容,还有很多的地方没有涉及.本文将讨论委托和事件一些更为细节的问题,包括一些 ...