`

《Pro Oracle SQL》CHAPTER 9 The Model Clause -- 9.6 Aggregation

阅读更多

Aggregation   聚合     (page 285)
    Data aggregation is commonly used in the data warehouse queries. The Model clause provides the
ability to aggregate the data using aggregate functions over the range of dimension columns. 
    数据聚合在数据仓库查询中很常用。Model子句提供使用聚合函数在维度列范围上聚合数据的能力。
    Many different aggregation function calls such as sum,  max,  avg,  stddev, and  OLAP function calls can be used to aggregate the data in a rule. It is easier to understand aggregation with an example.
    许多不同的聚合函数调用如sum,max,avg,stddev,以及OLAP函数调用能被用于在规则中聚合数据。通过实例较容易理解聚合。
     In Listing 9-16, the rule in lines 9 to 12 is calculating average inventory by Year using the clause
avg_inventory[year,ANY] = avg(inventory) [cv(year), week] . In the left hand side of the rule,
avg_invntory is the rule name. The first dimension in this rule is  Year  column .  As the dimension
clause is specifying the Week column as the second dimension, specifying ANY in the second position
of the rule argument matches with any value of week column including nulls.
In the right hand side of
the rule, the clause  avg(inventory) applies the  avg  function on the Inventory column. The first
dimension is cv(year). The second dimension is specified as  week. There is no need for the use of CV in
the second dimension, as the function must be applied on all weeks in the year as computed by the
clause cv(year). 

    列表9-16中,行9到12的规则按Year计算平均库存,使用子句avg_inventory[year,ANY] = avg(inventory) [cv(year), week] 。在规则的左手边,avg_invntory是规则名。规则的第一维度是Year列。因为维度子句指定Week列是第二维度,在规则参数的第二个位置上指 定ANY匹配任意week列值包括nulls。 在规则的右手边,子句avg(inventory) 在Inventory列上应用avg函数。第一维度是cv(year)。第二维度指定的是week。没有必要在第二维度上使用CV,因为函数必须应用于一年中的所有周上,按子句cv(year)计算。
    Line 13 shows the use of avg. Line 14 shows an example of using the  max function. 
    行13展示了avg的使用。行14展示了一个使用max函数的例子。
Listing 9-16.  Aggregation
 1    select product, country, year, week, inventory, avg_inventory, max_sale
 2        from sales_fact
 3        where country in ('Australia') and product ='Xtend Memory'
 4        model return updated rows
 5        partition by (product, country)
 6        dimension by (year, week)
 7        measures ( 0 inventory ,0  avg_inventory , 0 max_sale, sale, receipts)
 8        rules automatic order(
 9             inventory [year, week ] =
10                                      nvl(inventory [cv(year), cv(week)-1 ] ,0)
11                                       - sale[cv(year), cv(week) ] +
12                                       + receipts [cv(year), cv(week) ],
13              avg_inventory [ year,ANY ] = avg (inventory) [ cv(year), week ],
14              max_Sale [ year, ANY ]     = max( sale) [ cv(year), week ] 
15        )
16*     order by product, country,year, week
 
PRODUCT      COUNTRY     YEAR WEEK  INVENTORY AVG_INVENTORY  MAX_SALE
------------ ---------- ----- ---- ---------- ------------- ---------
...
Xtend Memory Australia   2001   42     17.532         28.60    278.44
Xtend Memory Australia   2001   43     24.511         28.60    278.44
Xtend Memory Australia   2001   44     29.169         28.60    278.44
...
Xtend Memory Australia   2001   52    -22.931         28.60    278.44

 

 

 

0
0
分享到:
评论

相关推荐

    《Pro Oracle SQL》CHAPTER 9 The Model Clause -- 9.4Returning Updated Rows

    《Pro Oracle SQL》一书的第9章深入探讨了Oracle数据库中的"Model"子句,这一章节重点关注如何使用Model子句来更新数据行。在Oracle SQL中,Model子句是一种强大的功能,允许进行复杂的行处理和模拟迭代计算,通常...

    《Pro Oracle SQL》CHAPTER 9 The Model Clause -- 9.5 Evaluation Order

    《Pro Oracle SQL》一书的第9章深入探讨了Oracle数据库中的“Model”子句,这一章节重点关注了9.5节——评估顺序。在Oracle SQL中,Model子句是一种高级的行处理工具,用于进行复杂的行计算和模拟迭代过程,比如解决...

    《Pro Oracle SQL》CHAPTER 9 The Model Clause -- 9.7 Iteration

    《Pro Oracle SQL》一书中的第9章详细探讨了Oracle SQL中的“模型”子句,这一章的主题是“9.7 迭代”。在Oracle数据库中,模型子句是一种强大的功能,它允许用户进行复杂的多步骤计算,尤其适用于处理数组、矩阵...

    《Pro Oracle SQL》CHAPTER 9 The Model Clause -- 9.3 Positional and Symbolic Refere

    《Pro Oracle SQL》一书中的第9章详细探讨了Oracle SQL中的“模型”子句,这一章重点关注了位置引用和符号引用的概念。在Oracle数据库中,模型子句是一种强大的工具,用于处理复杂的行列操作,例如数据建模、数据...

    《Pro Oracle SQL》CHAPTER 9 -- 9.2 Inter-Row Referencing via the Model clause

    《Pro Oracle SQL》是Oracle数据库查询的一本权威指南,其中第9章主要讲解了如何使用Model子句进行行间引用,这是一个高级SQL特性,用于处理复杂的行与行之间的计算和逻辑操作。9.2章节专注于Inter-Row Referencing...

    《Pro Oracle SQL》CHAPTER 9 -- 9.10Performance Tuning with the Model Clause

    《Pro Oracle SQL》一书的第9章,重点关注了使用"Model"子句进行性能调优的方法。在Oracle数据库中,Model子句是一种强大的功能,它允许数据建模和复杂的计算,尤其适用于解决多步骤计算问题,如模拟、预测和序列...

    《Pro Oracle SQL》Chapter7 Advanced Grouping -- 7.2HAVING Clause

    《Pro Oracle SQL》一书的第七章深入探讨了高级分组技术,特别是关于`HAVING`子句的部分。`HAVING`子句在SQL查询中扮演着至关重要的角色,它用于在聚合函数的结果集上设置条件,这与`WHERE`子句有所不同。`WHERE`...

    Pro Oracle SQL

    Pro Oracle SQL unlocks the power of SQL in the Oracle Database—one of the most potent SQL implementations on the market today. To master it requires a three-pronged approach: learn the language ...

    oracle advanced sql 高级SQL教程 ORACLE官方教材

    Walking the Tree: From the Top Down 5-9 Ranking Rows with the LEVEL Pseudocolumn 5-10 Formatting Hierarchical Reports Using LEVEL and LPAD 5-11 Pruning Branches 5-13 Summary 5-14 Practice 5 Overview 5...

    Oracle SQL 优化与调优技术详解-附录:SQL提示.pdf

    ### Oracle SQL 优化与调优技术详解:深入理解SQL提示 #### 一、SQL提示的定义及作用 在Oracle数据库的SQL语句中,SQL提示(Hints)是一种用于指导优化器选择特定执行计划的特殊注释语法。这些提示能够帮助数据库...

    Clause-view个人中心、设置常用的itemview

    Clause-view个人中心、设置常用的itemview

    Python库 | clause-1.1.2.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:clause-1.1.2.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Oracle和SqlServer语法区别

    Oracle和SqlServer语法区别 Oracle和SqlServer是两种流行的关系型数据库管理系统,它们之间存在着一些语法区别。了解这些区别对于开发者来说非常重要,因为它可以帮助他们更好地迁移到新的数据库管理系统。下面将...

    ORACLE和SQL Server的语法区别

    ### ORACLE和SQL Server的语法区别 #### 一、概述 本文主要介绍Oracle与SQL Server在SQL语言层面的异同之处,重点在于Transact-SQL(T-SQL)与PL/SQL之间的区别,并提供了一些迁移策略。对于希望将现有的Oracle...

    Oracle SQL查考手册chm

    Oracle SQL查考手册是一部关于Oracle数据库查询语言的重要参考资料,它涵盖了运算符、表达式、条件、函数以及常见的SQL DDL(Data Definition Language)和Clause等内容。这篇总结将深入解析这些核心概念,帮助读者...

    Chatopera 语义理解系统:机器学习,聊天机器人,意图识别clause-osc.zip

    Chatopera 语义理解系统:机器学习,聊天机器人,意图识别clause-osc.zip

    SSD7 选择题。Multiple-Choice

    (b) the name of the table, the names of the table's attributes, the data types of the table's attributes, the formats of the table's attributes, and the maximum number of rows that the table can have...

Global site tag (gtag.js) - Google Analytics