[每日一题] OCP1z0-047 :2013-08-15 描述GROUPING 函数 .......................................43
正确答案: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的更多相关文章
- [每日一题] OCP1z0-047 :2013-08-06 外表部――相关描述
这道题目的知识点是要你熟悉外部表,怎么建外部表,外部表的数据是怎么存储的等等.请给出正确答案,并解释A B C D每项,最好用实验测试证明! 外部表的metadata(元数据)是存在数据库中,但它的数 ...
- [每日一题] OCP1z0-047 :2013-08-12 view视图的描述哪些是正确的?
正确答案是: CE 这是OCP教材中的: 1.简单视图与复杂视图的定义: 2.复杂视图通常不能被DML: .WITH CHECKOP TIONT选项 A不正确.简单视图可以被更新. hr@OCM> ...
- 【js】Leetcode每日一题-数组异或操作
[js]Leetcode每日一题-数组异或操作 [题目描述] 给你两个整数,n 和 start . 数组 nums 定义为:nums[i] = start + 2*i(下标从 0 开始)且 n == ...
- 【JavaScript】Leetcode每日一题-平方数之和
[JavaScript]Leetcode每日一题-平方数之和 [题目描述] 给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c . 示例1: 输入:c = 5 ...
- 【JavaScript】Leetcode每日一题-递增顺序搜索树
[JavaScript]Leetcode每日一题-递增顺序搜索树 [题目描述] 给你一棵二叉搜索树,请你 按中序遍历 将其重新排列为一棵递增顺序搜索树,使树中最左边的节点成为树的根节点,并且每个节点没 ...
- 【JavaScript】Leetcode每日一题-组合总和4
[JavaScript]Leetcode每日一题-组合总和4 [题目描述] 给你一个由 不同 整数组成的数组 nums ,和一个目标整数 target .请你从 nums 中找出并返回总和为 targ ...
- 【JavaScript】Leetcode每日一题-最大整除子集
[JavaScript]Leetcode每日一题-最大整除子集 [题目描述] 给你一个由 无重复 正整数组成的集合 nums ,请你找出并返回其中最大的整除子集 answer ,子集中每一元素对(an ...
- 【JavaScript】Leetcode每日一题-移除元素
[JavaScript]Leetcode每日一题-移除元素 [题目描述] 给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度. 不要使用 ...
- 【python】Leetcode每日一题-丑数2
[python]Leetcode每日一题-丑数2 [题目描述] 给你一个整数 n ,请你找出并返回第 n 个 丑数 . 丑数 就是只包含质因数 2.3 和/或 5 的正整数. 示例1: 输入:n = ...
随机推荐
- .Net使用SSH.NET通过SSH访问Linux主机
使用了SSH.NET库,添加引用dll至项目,以下代码显示了点击按钮后SSH链接Linux主机执行命令并返回命令执行结果 protected void btnExcute_Click(object s ...
- android获取在res文件下的图片资源
//得到该图片的id(name 是该图片的名字,"drawable" 是该图片存放的目录,getPackageName()是应用程序的包) int resID = getResou ...
- libthrift0.9.0解析(二)之TSimpleServer
TSimpleServer简单实现Tserver,代码如下. /** * Simple singlethreaded server for testing. * */ public class TSi ...
- sql查询每门课程成绩最高的学生
给出数据库(sco)如下图: 查出每门课程成绩最高的学生 select b.id,b.kemu,b.name,b.chengji from (select kemu,max(chengji) maxc ...
- 转自:http://blog.sina.com.cn/s/blog_86e874d30101e3d8.html(谢谢原文作者),Win7下安装CentOS 6.5双系统
经过一下午的折腾,终于在64位的Windows 7上面成功安装了CentOS 6.5(64bit)系统,中途因为硬盘分区的问题失败了一次.下面是安装过程: 在安装过程中借助了这篇文章的内容:http: ...
- Windows 中JDK安装配置教程
1.准备工作 a.因为Java JDK区分32位和64位系统,所以在安装之前必须先要判断以下我们的系统为多少位系统.右键计算机-属性查看,我安装的是64位 b.下载JDK,地址:http://www. ...
- 阿里云服务器上使用iptables设置安全策略
转自:http://www.netingcn.com/aliyun-iptables.html 公司的产品一直运行在云服务器上,从而有幸接触过aws的ec2,盛大的云服务器,最近准备有使用阿里云的弹性 ...
- IOS之动画
IOS之动画 15.1 动画介绍 15.2 Core Animation基础 15.3 隐式动画 15.4 显式动画 15.5 关键帧显式动画 15.6 UIView级别动画 15.1 动画介绍 ...
- 移植rom移动TD到联通W
1.修改build.prop TD为 ril.flightmode.poweroffMD=0 ril.telephony.mode=2 改为 ril.flightmode.poweroffMD=1 r ...
- Web API的CPU占用100%
我用Web API做了一个网站,网站很简单,请求就是几个普通的参数,提交到服务器后,在Web API里做一下参数验证,然后去访问Redis里的TIME命令,最后把TIME命令返回的结果计算出yyyy- ...