Oracle Discoverer Desktop User's Guide 10g (9.0.4) for Windows Part Number B10272-01 |
|
This appendix contains the following sections:
For more information about Analytic Functions, and Oracle functions in general, refer to the following Oracle publications:
The examples in the following sections use the Video Stores Tutorial.
The examples in this chapter use the following additional formatting:
This section provides the following examples to help you create Calculations.
NOTE: For more information on how to create Calculations, refer to Section 8.3, "Creating Calculations.". |
This example calculates the number of rows returned by a query.
This example calculates a 25% increase in sales figures.
As well as the extensive range of mathematical functions available in Discoverer, you also have access to a wide range of number and text formatting functions. This example uses a Calculation to re-format City text data to upper-case.
Oracle Discoverer supports the Analytic Functions that are included in Oracle Server 8.1.6 and above. Discoverer also extends the functionality of standard SQL by allowing you to nest Analytic Functions. You can use these advanced functions to perform sophisticated analysis on your data.
This section contains the following sub-sections:
Analytic Functions are classified in the following categories:
When you use Analytic Functions, note that they have a precise definition which does not change as you drill, pivot, or sort the result set. For example, if you use the RANK function to assign ranks to sales figures partitioned by Quarter, if you drill down the Month level, the rank still only applies to the Quarter level.
When creating Analytic Functions in Discoverer, you can either type or paste them directly into the Calculation dialog box, or you can select them from the function list.
If you select them from the function list, you are presented with a generic Analytic Function Template that helps you define the function by telling you what information you may need to provide. Templates should be used as a guide. Because templates are designed to cover most types of usage, you will not always need to use every part of the template.
For example, when you paste a new RANK Analytic Function into a calculation box, Discoverer provides the following template:
Although you can define a complex function using both expressions (expr1 and expr2), you can often define a simple function using only the ORDER BY expression; for example:
NOTE: By default, results data is sorted in ascending order (ASC), nulls first (NULLS FIRST).
For more information about expressions used by the Analytic Function template, refer to "More about the Analytic Function Template".
Ranking functions compute the rank of an item with respect to other items in an ordered list.
This example ranks to a set of sales figures.
This example ranks a set of sales figures within each Region for each Year.
This example ranks a set of sales figures and displays the top three selling Cities for each Region.
Workbook options | Details |
---|---|
Select Items |
Video Analysis Information: Year (Calendar Year), Region, City, Sales SUM |
Sort Order |
Year, Region |
Conditions |
Department = Video Sale OR Department = Video Rental Rank Top <= 3 |
Calculation Name |
Rank Top |
Calculation |
RANK() OVER(PARTITION BY Year, Region ORDER BY Sales SUM DESC) |
Tip |
To quickly filter the list to the first, second, or third ranked cities, pivot the Rank Top item to the page axis, (see also Section 4.1.2, "Pivoting Data on a Table"). |
Display Data |
This example ranks a set of sales figures and displays the top three and bottom three performing Cities per Region.
Banding is a type of ranking that divides a list of values in a partition into a specified number of groups called Bands (also known as buckets) and assigns each value to a Band.
Two common types of banding are:
Here, the function typically takes the largest value minus the lowest value, and divides the result by the number of bands required. This value defines the range of each Band.
Values are then assigned to bands according to which range they fall into. Therefore, the number of values in each Band may differ. For example, if we have 100 values and divide them into four equi-width bands, each band may contain different numbers of values.
Use the GREATEST function or the CASE function to produce equi-width bands based on value.
Here, the function divides the number of values in the partition by the number of bands, which gives the number of values in each band.
An equal number of values are then placed in each band. For example, if we have 100 values and divide them into four equi-height bands, each band contains 25 values.
Use the NTILE function to produce equi-height bands based on rank.
This example divides Sales figures into bands according to their value, (also known as equi-width bands).
This example creates the same results as the example in "Producing equi-width Bands (1)", except that it uses a CASE statement rather than the GREATEST function.
Again, the example divides Sales figures into bands according to their value, using a CASE function, (see also "Producing equi-width Bands (1)").
This example assigns a set of sales figures into two equi-height Bands.
Windowing functions are used to compute aggregates using values from other rows. For example, cumulative, moving, and centered aggregates.
Two common types of windowing are:
For example, if we have a list of monthly sales figures, a logical window could compute a moving average of the previous three months, (inclusive of the current month).
When calculating the average, the calculation assumes a NULL value for months missing from the list. In the example, the three-month moving average for November assumes NULL values for the missing months September and October.
For example, if we have a list of monthly sales figures, a physical window could compute a moving average of the previous three rows ignoring missing months.
When calculating the average, the calculation ignores months missing from the list. In the example, the three-month moving average for November uses June, July, and November in the calculation.
This example uses a logical window to calculate a moving three month Sales average.
This example uses a physical window to calculate the cumulative value of sales.
Reporting functions are used to compute aggregates.
This example calculates annual sales by Year.
This example calculates the total annual sales by Year and Region.
This example calculates the percentage of annual sales per Region for each City in each Year.
This example calculates sales as a percentage of total Sales.
LAG and LEAD functions are typically used to compare values in different time periods. For example, compare sales figures in 2000 with sales figures in 2001.
This example compares sales figures across time.
Using the comparative sales figures from example 11.8.2, this example calculates the sales growth across time.
Using the comparative sales figures from examples A.2.8.2 and A.2.8.3, this example ranks sales growth by year.
Statistics functions are used to compute covariance, correlation, and linear regression statistics. Each function operates on an unordered set. They also can be used as windowing and reporting functions.
This example computes an ordinary least-squares regression line that expresses the Profit SUM per Month as a linear function of its Sales SUM. The following functions are used:
When you paste a new Analytic Function into a Calculation box, Discoverer provides the following generic template:
The expressions are used as follows.
For more information about Oracle expressions, refer to "Getting More Information".
When you use Analytic Functions in Conditions, the way that you combine them with non-Analytic Functions affects the Discoverer data returned by the query. The following sequencing rules apply:
Text description of the illustration order1.gif
In the example above, the `Region = `Central' condition is applied first, then the Rank is computed, then the `Rank <= 3' condition is applied, (which contains an Analytic function).
Text description of the illustration order3.gif
In the example above, the Rank is evaluated, then the `Rank <= 3' condition is applied, then the `Region = `Central' condition is applied.
To illustrate how sequencing affects the Discoverer data returned by a query, consider the following two scenarios.
In the first scenario above, we apply two simple Conditions: Region = `Central', and Rank <= 3 (where Rank is an Analytic Function). The Region = `Central' condition is applied first, then Rank <= 3. Therefore, only Sales figures for the Central Region that have a ranking of three or less are included in the Results Set.
In the second scenario above, we apply a single advanced Condition: Region = `Central' AND Rank <= 3, (where Rank is an Analytic Function). The Rank <= 3 condition is applied first, then the Region = `Central' condition. Therefore, only figures in the Central Region that have an overall ranking of three or less are included in the Results Set.
|
![]() Copyright © 1996, 2003 Oracle Corporation. All Rights Reserved. |
|