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
相关解决方案
- 求教,SSH + ORACLE 日期处理有关问题
- hibernate 连接 oracle session 有关问题
- eclipse+tomcat6.0+oracle 10g配置数据库连接池的异常
- java 生成 word 封存到 oracle 数据库
- oracle 最大连市接数 为什么main方法无限拿连接
- oracle 分页排序,ssi,该怎么处理
- oracle 最近的时间(而不是前一天的时间) 跪求sql语句 。解决方法
- java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:192.168解决思路
- java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver,该怎么处理
- Jsp + Oracle 怎么取回id,报错getInt not implemented for class oracle.jdbc.driver.T4CRo
- oracle 调用java程序,该如何处理
- oracle,该怎么解决
- 在 Hibernate3 查询不到 Oracle 11g 里的记录
- Oracle 评论排序!该怎么解决
- oracle 安装时出现 java tm 异常
- android访问其他数据库(如:oracle、MySql等),希望大家给点建议!解决方案
- oracle sql 有关问题
- oracle 安插 LONG VARCHAR 类型数据
- jdbc+oracle 11中文乱码(英文一般)-在线盼
- ORACLE 一条SQL的有关问题
- oracle loadjava如何用
- netbeans desktop Application 连 Oracle 数据库的有关问题
- Oracle 每天数据备份
- oracle,该如何处理
- Crystal Reports 高版本如果在低版本打开,该怎么处理
- C# + SQL server +oracle QQ交流群142703980解决方法
- 求 dotConnect for Oracle 控件破解解决方法
- 求一个Stimulsoft Reports .Net的web范例
- 收集意见,招募斑竹,CSDN 拟开设《Crystal Reports》大论坛…
- grove 怎么连 oracle 数据库