正确答案: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. MSSQL 简单练习回顾

    这段时间,报了浦软培训的.NET,现在整理回顾下,算是个小小总结吧 为了便于操作,我没有在多个数据库间切换数据库实例,以一个总的数据库实例 test_demo为源进行的相关操作,代码的注释根据我的理解 ...

  2. Cacti监控Windows主机,Windows主机的正确配置

    使用cacti监控Windows主机的时候经常遇到无法获取Windows主机的snmp信息和Windows主机的硬件信息,主要原因是Windows主机没有正确配置snmp,以下是正确的配置步骤:1.安 ...

  3. windows下安装mysql笔记

    接着上几篇文章再来看下windows下安装mysql. 我这里是windows7 64位, 安装过程中还是遇到一些坑,这里记录下. 一.下载安装包 打开mysql官网下载页面:http://dev.m ...

  4. 1.Tomcat配置

    1.启动 解压缩安装包后,点击startup.bat,保持控制台窗口开启 浏览器中输入http://localhost:8080 后看到启动界面则表示启动成功 点击shutdown.bat则关闭Tom ...

  5. 我自己的style

    /** DATE:Time AUTHOR:Zoe TEAM:公司名称 INTRO:cssName **/ @charset "utf-8"; /*通用公共样式 开始*/ /* 清除 ...

  6. php设计模式2策略模式

    <?php /** ****************************************************** * 策略模式:策略模式针对一组算法,将每一个算法封装到具有共同接 ...

  7. str_repeat() 函数

    <?php echo str_repeat(".",13);//重复几次 ?>

  8. ionic android app 签名处理

    第一步:生成签名证书. y@y:my_temp$ $ keytool -genkey -v -keystore my-release-key.keystore -alias ydkt -keyalg ...

  9. Android对ScrollView滚动监听,实现美团、大众点评的购买悬浮效果

    转帖请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/17761431),请尊重他人的辛勤劳动成果,谢谢! 我之前写 ...

  10. maven下载及配置

    Maven是一个采用纯Java编写的开 源项目管理工具.Maven采用了一种被称之为project object model (POM)概念来管理项目,所有的项目配置信息都被定义在一个叫做POM.xm ...