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》Chapter7 - 7.7Extending Reports with GROUPING()
热度:229 发布时间:2016-05-05 15:01:10.0
相关解决方案
- oracle 分页排序,ssi,该怎么处理
- oracle 最近的时间(而不是前一天的时间) 跪求sql语句 。解决方法
- oracle,该怎么解决
- 在 Hibernate3 查询不到 Oracle 11g 里的记录
- oracle 安装时出现 java tm 异常
- android访问其他数据库(如:oracle、MySql等),希望大家给点建议!解决方案
- oracle 安插 LONG VARCHAR 类型数据
- ORACLE 一条SQL的有关问题
- oracle loadjava如何用
- oracle,该如何处理
- Crystal Reports 高版本如果在低版本打开,该怎么处理
- C# + SQL server +oracle QQ交流群142703980解决方法
- 求一个Stimulsoft Reports .Net的web范例
- [分享]Crystal Reports 2008 (设计篇)- 参数字段设立及子报表开发
- [分享]Crystal Reports 2008 (设计篇)- 装配及新建报表文档
- 64位WIN7,安装Crystal reports XI Release 2的有关问题
- 在asp.net中使用Crystal Reports 画柱状图时,它的默认图例总是“字段.”解决思路
- [分享]Crystal Reports 2008 (设计篇)- 参数字段设置及子报表开发解决方案
- 关于Crystal Reports 11.5 for .net 2005 汇出到excel 2000的有关问题
- [分享]Crystal Reports 2008 (设计篇)- 格式设计、报表嵌入以及有关问题BUG解决办法补充
- [分享]Crystal Reports 2008 (设计篇)- 安装及新建报表文档,该如何处理
- [Crystal Reports]在ASP.net web中导出 有关问题[Excel、Word、PDF]
- Crystal Reports XI Release 2怎么制作折线柱状的混合图
- 怎么跟踪winform应用程序发送到数据库的sql(oracle、mssql)
- , 每次玩ASP都会遇到一些恶心的有关问题, 这次是:未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项
- 尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运,该怎么解决
- 求解:gridview行值的计算并绑定有关问题(asp.net+oracle)
- Oracle.DataAccess 执行多条sql语句,该如何解决
- VS10连接Oracle的有关问题:"Oracle.DataAccess.Client.OracleConnection"的类型初始值设定项引发错误
- System.Data.OleDb.OleDbException: 未找到 Oracle 客户端和网络组件。