7.7Extending Reports with GROUPING() 用GROUPING()函数扩展报告 (page209)
Another use of GROUPING() is in the HAVING clause, where it can be used to control which aggregation levels appear in the output.
The report seen in previous examples creates about five pages of output, which may be more than the customer cares to see. By using the GROUPING() function, these aggregations can be condensed
to roll up the totals for either or all of the columns used in the CUBE extension.
Several variations of GROUPING() have been used to modify the previous SQL. The modifications and resulting output are shown in Listing 7-14.
GROUPING()函数的另一种用法是在HAVING子句中运用,在那里(运用可用)来控制哪个层次的聚合出现在输出中。
在之前例子报告中,创建了大约5页的输出,可能比起客户关心的数据要多一些。通过使用GROUPING()函数,(可控制)哪些聚合行能被浓缩(
扼要
)
,对CUBE扩展式中出现的一列或多列进行累计求和。
把GROUPING()函数的几个变换应用到对之前的SQL的修改中。修改和结果输出都展示在列表7-14当中了。
Examining the data in Listing 7-14 you can see that applying GROUPING() to the CUST_INCOME_LEVEL column created aggregates from all AGE_RANGE values to be accumulated across all income levels. Doing so for the AGE_RANGE column had similar effects, with totals aggregated for all values of INCOME_LEVEL without regard to the value of AGE_RANGE. Including all of the columns from the CUBE extension as arguments to the GROUPING() function will cause the aggregations to be condensed to a single row, similar to what could be done with SUM(PROFIT) and a simple GROUP BY PROD_CATEGORY.
Using the CUBE extension, however, allows simple changes to the HAVING clause to create several different reports.
检查列表7-14的数据你可以发现,把GROUP()函数应用于CUST_INCOME_LEVEL列,将创建跨越所有收入层级的所有 AGE_RANGE值的聚合。同样应用于AGE_RANGE列,也会有相似的效果,将创建不论年龄范围聚合所有INCOME_LEVEL值的总数。若GROUPING()函数包含CUBE扩展的所有列,将使得聚合浓缩成一行。与一个简单的GROUP BY PROD_CATEGORY,然后SUM(PROFIT)有异曲同工之效。
然而,使用CUBE扩展,允许简单的改变HAVING子句来创建好些不同的报告。
Listing 7-14. GROUPING() in the HAVING Clause HAVING子句中的GROUPING()
CUST_INCOME_LEVEL
35 group by prod_category, cube(cust_income_level,age_range)
36 having grouping(cust_income_level)=1
QUERY AGE
TAG PRODUCT CATEGORY INCOME LEVEL RANGE PROFIT
------ ------------------------------ -------------------- -------- ---------------
Q3 Hardware ALL INCOME 60-70 $85,314.04
Q3 Hardware ALL INCOME 10-20 $90,849.87
Q3 Hardware ALL INCOME 0-10 $92,207.47
...
Q4 Hardware ALL INCOME ALL AGE $987,386.78
AGE_RANGE
35 group by prod_category, cube(cust_income_level,age_range)
36 having grouping(age_range)=1
QUERY AGE
TAG PRODUCT CATEGORY INCOME LEVEL RANGE PROFIT
------ ------------------------------ -------------------- -------- ---------------
Q2 Hardware K: 250,000 - 299,999 ALL AGE $26,678.00
Q2 Hardware L: 300,000 and above ALL AGE $28,974.28
Q2 Hardware J: 190,000 - 249,999 ALL AGE $43,761.47
...
Q4 Hardware ALL INCOME ALL AGE $987,386.78
CUST_INCOME_LEVEL, AGE_RANGE
35 group by prod_category, cube(cust_income_level,age_range)
36 having grouping(cust_income_level)=1 and grouping(age_range)=1
QUERY AGE
TAG PRODUCT CATEGORY INCOME LEVEL RANGE PROFIT
------ ------------------------------ -------------------- -------- ---------------
Q4 Electronics ALL INCOME ALL AGE $838,994.19
Q4 Hardware ALL INCOME ALL AGE $987,386.78
Q4 Peripherals and Accessories ALL INCOME ALL AGE $1,751,079.16
Q4 Photo ALL INCOME ALL AGE $1,570,866.04
Q4 Software/Other ALL INCOME ALL AGE $873,603.25
分享到:
相关推荐
《Pro Oracle SQL》一书的第七章第7.8节主要探讨了如何通过GROUPING_ID()函数来扩展Oracle SQL报告的功能。GROUPING_ID()在数据分析和报表生成中扮演着重要角色,尤其在处理分组数据时,能提供更详细的分组信息。本...
Design of Embedded Systems Chapter XII - Describing and Extending Classes with XMI—An Industrial Experience Index List of Figures List of Tables List of Definitions
Design of Embedded Systems Chapter XII - Describing and Extending Classes with XMI—An Industrial Experience Index List of Figures List of Tables List of Definitions
Chapter 2 - Small Victories—Creating Projects With IDE’s Chapter 3 - Project Walkthrough—An Extended Example Chapter 4 - Computers, Programs, & Algorithms Part II - C++ Language Chapter 5 ...
NAS-BENCH-201扩展了可重现神经架构搜索的范围,这是计算机视觉领域的一个重要议题。NAS(Neural Architecture Search,神经架构搜索)近年来在多个应用场景中取得了突破性的成功。NAS的目标是自动发现最优的神经...
### Oracle Hyperion Essbase-Extending Essbase Reporting Capabilities 培训资料解析 #### 一、Hyperion Reports概述 **Oracle Hyperion Essbase** 是一个高性能的在线分析处理(OLAP)平台,广泛应用于财务规划...
The book will take the reader on a journey of building an app for iOS and extending the app to a different platform, such as the web and tvOS. The app will start out simple, but get more and more ...
Extending Unity with Editor Scripting 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请...
EXTENDING SPARK WITH JAVA AGENTS EXTENDING SPARK WITH JAVA AGENTS是指使用Java代理扩展Spark的功能,以提高性能和优化大数据应用程序的性能。该技术主要涉及到Spark缓存和Java代理的集成,旨在解决Spark缓存...
综上所述,《嵌入式Android - Porting, Extending and Customizing》这本书不仅深入浅出地讲解了如何将Android系统移植到各种嵌入式设备上,还提供了大量的实践案例和实用技巧,对于希望在这个领域有所作为的专业...
《Extending Unity with Editor Scripting 彩色高清无水印》是一本专注于Unity游戏引擎编辑器扩展的专业书籍,旨在帮助开发者充分利用Unity的Editor脚本功能,创建高效且定制化的开发工具。通过本书,读者可以深入...
《Extending Unity with Editor Scripting》是关于如何使用Unity编辑器脚本扩展Unity引擎的一份详细指南,这本书由Angelo Tadres撰写,并由Packt Publishing出版。书中提供了丰富的信息,旨在帮助Unity(通常称为U3D...
在IT领域,特别是地理信息系统(GIS)行业中,Python与ArcGIS的结合已成为提升工作效率和扩展功能的关键技术之一。本文将深入解析如何通过Python脚本来增强ArcGIS的功能,以及为何选择Python作为ArcGIS的脚本语言。...
《Extending the Linear Model with R》这本书主要探讨了如何通过R语言来扩展传统的线性模型,涵盖了一系列高级统计方法,包括广义线性模型、混合效应模型以及非参数回归等。这些模型和技术对于处理复杂数据集及进行...
[Packt Publishing] Applying and Extending Oracle Spatial (E-Book) ☆ 图书概要:☆ Overview Understand how to develop Oracle Spatial data models and applications that use PL/SQL and Java to solve ...
Table of Contents ... Chapter 7 - AI-Based Problem Solving Chapter 8 - Building a Custom STL Container Chapter 9 - A Mini C++ Interpreter Index List of Figures List of Tables
藏经阁-EXTENDING SPARK WITH JAVA AGENTS spark 是一个基于内存的计算引擎,能够快速地处理大规模数据,但spark 的性能优化是非常重要的。spark 提供了 caching 机制来提高性能,但是 caching 的使用需要谨慎,...