Siebel Analytics Server Administration Guide > SQL Reference > SQL Reference >

Aggregate Functions


Aggregate functions perform work on multiple values to create summary results. The aggregate functions cannot be used to form nested aggregation in expressions on logical columns that have a default aggregation rule defined in the Aggregation tab of the Logical Column dialog box. To specify nested aggregation, you need to define a column with a default aggregation rule and then request the aggregation of the column in a SQL statement.

Avg

Calculates the average (mean) value of an expression in a result set. Has to take a numeric expression as its argument.

Syntax:

AVG (n_expression)

where:

n_expression
Any expression that evaluates to a numerical value.

AvgDistinct

Calculates the average (mean) of all distinct values of an expression. Has to take a numeric expression as its argument.

Syntax:

AVG (DISTINCT n_expression)

where:

n_expression
Any expression that evaluates to a numerical value.

BottomN

Ranks the lowest n values of the expression argument from 1 to n, 1 corresponding to the lowest numerical value. The BOTTOMN function operates on the values returned in the result set.

Syntax:

BOTTOMN (n_expression, n)

where:

n_expression
Any expression that evaluates to a numerical value.
n_expression
Any positive integer. Represents the bottom number of rankings displayed in the result set, 1 being the lowest rank.

NOTE:  A query can contain only one BOTTOMN expression.

Count

Calculates the number of rows having a nonnull value for the expression. The expression is typically a column name, in which case the number of rows with nonnull values for that column is returned.

Syntax:

COUNT (expression)

where:

expression
Any expression.

CountDistinct

Adds distinct processing to the COUNT function.

Syntax:

COUNT (DISTINCT expression)

where:

expression
Any expression.

Count (*) (CountStar)

Counts the number of rows.

Syntax:

COUNT(*)

For example, if a table named Facts contained 200,000,000 rows, the following query would return the following results:

SELECT COUNT(*) FROM Facts

COUNT(*)

200000000

First

Selects the first returned value of the numeric expression argument. The FIRST function is limited to defining dimension-specific aggregation rules in a repository. You cannot use it in SQL statements.

The FIRST function operates at the most detailed level specified in your explicitly defined dimension. For example, if you have a time dimension defined with hierarchy levels day, month, and year, the FIRST function returns the first n days.

You should not use the FIRST function as the first dimension-specific aggregate rule; doing so can cause poor performance because it might cause queries to bring back large numbers of rows for processing in the Siebel Analytics Server.

Syntax:

FIRST (n_expression)

where:

n_expression
Any expression that evaluates to a numerical value.

GroupByColumn

For use in setting up aggregate navigation. It specifies the logical columns that define the level of the aggregate data existing in a physical aggregate table.

For example, if an aggregate table contains data grouped by store and by month, specify the following syntax in the content filter (General tab of Logical Source dialog):

GROUPBYCOLUMN(STORE, MONTH)

The GROUPBYCOLUMN function is only for use in configuring a repository; you cannot use it to form SQL statements.

GroupByLevel

For use in setting up aggregate navigation. It specifies the dimension levels that define the level of the aggregate data existing in a physical aggregate table.

For example, if an aggregate table contains data at the store and month levels, and if you have defined dimensions (Geography and Customers) containing these levels, specify the following syntax in the content filter (General tab of Logical Source dialog):

GROUPBYLEVEL (GEOGRAPHY.STORE, CUSTOMERS.MONTH)

The GROUPBYLEVEL function is only for use in configuring a repository; you cannot use it to form SQL statements.

Last

Selects the last returned value of the numeric expression. The LAST function is limited to defining dimension-specific aggregation rules in a repository; you cannot use it in SQL statements.

The LAST function operates at the most detailed level specified in your explicitly defined dimension. For example, if you have a time dimension defined with hierarchy levels day, month, and year, the LAST function returns the last n days.

You should not use the LAST function as the first dimension-specific aggregate rule; doing so can cause poor performance because it might cause queries to bring back large numbers of rows for processing in the Siebel Analytics Server.

Syntax:

LAST (n_expression)

where:

n_expression
Any expression that evaluates to a numerical value.

Max

Calculates the maximum value (highest numeric value) of the rows satisfying the numeric expression argument.

Syntax:

MAX (expression)

where:

expression
Any expression.

The MAX function resets its values for each group in the query, according to the rules outlined in Display Function Reset Behavior.

Median

Calculates the median (middle) value of the rows satisfying the numeric expression argument. When there are an even number of rows, the median is the mean of the two middle rows. This function always returns a double.

Syntax:

MEDIAN (n_expression)

where:

n_expression
Any expression that evaluates to a numerical value.

The MEDIAN function resets its values for each group in the query, according to the rules outlined in Display Function Reset Behavior.

Min

Calculates the minimum value (lowest numeric value) of the rows satisfying the numeric expression argument.

Syntax:

MIN (expression)

where:

expression
Any expression.

The MIN function resets its values for each group in the query, according to the rules outlined in Display Function Reset Behavior.

NTile

The NTILE function determines the rank of a value in terms of a user-specified range. It returns integers to represent any range of ranks. In other words, the resulting sorted data set is broken into a number of tiles where there are roughly an equal number of values in each tile.

Syntax:

NTILE (n_expression, n)

where:

n_expression
Any expression that evaluates to a numerical value.
n
A positive, nonnull integer that represents the number of tiles.

If the n_expression argument is not NULL, the function returns an integer that represents a rank within the requested range.

NTile with n=100 returns what is commonly called the percentile (with numbers ranging from 1 to 100, with 100 representing the high end of the sort). This value is different from the results of the Siebel Analytics Server percentile function, which conforms to what is called percent rank in SQL 92 and returns values from 0 to 1.

Percentile

Calculates a percent rank for each value satisfying the numeric expression argument. The percent rank ranges are from 0 (1st percentile) to 1 (100th percentile), inclusive.

The PERCENTILE function calculates the percentile based on the values in the result set of the query.

Syntax:

PERCENTILE (n_expression)

where:

n_expression
Any expression that evaluates to a numerical value.

The PERCENTILE function resets its values for each group in the query according to the rules outlined in Display Function Reset Behavior.

Rank

Calculates the rank for each value satisfying the numeric expression argument. The highest number is assigned a rank of 1, and each successive rank is assigned the next consecutive integer (2, 3, 4,...). If certain values are equal, they are assigned the same rank (for example, 1, 1, 1, 4, 5, 5, 7...).

The RANK function calculates the rank based on the values in the result set of the query.

Syntax:

RANK (n_expression)

where:

n_expression
Any expression that evaluates to a numerical value.

The RANK function resets its values for each group in the query according to the rules outlined in Display Function Reset Behavior.

StdDev

The STDDEV function returns the standard deviation for a set of values. The return type is always a double.

Syntax:

STDDEV([ALL | DISTINCT] n_expression)

where:

n_expression
Any expression that evaluates to a numerical value.

There are two other functions that are related to STDDEV:

STDDEV_POP([ALL | DISTINCT] n_expression)

STDDEV_SAMP([ALL | DISTINCT] n_expression)

STDDEV and STDDEV_SAMP are synonyms.

The STDDEV function resets its values for each group in the query according to the rules outlined in Display Function Reset Behavior.

Sum

Calculates the sum obtained by adding up all values satisfying the numeric expression argument.

Syntax:

SUM (n_expression)

where:

n_expression
Any expression that evaluates to a numerical value.

The SUM function resets its values for each group in the query according to the rules outlined in Display Function Reset Behavior.

SumDistinct

Calculates the sum obtained by adding all of the distinct values satisfying the numeric expression argument.

Syntax:

SUM(DISTINCT n_expression)

where:

n_expression
Any expression that evaluates to a numerical value.

TopN

Ranks the highest n values of the expression argument from 1 to n, 1 corresponding to the highest numerical value.

The TOPN function operates on the values returned in the result set.

Syntax:

TOPN (n_expression, n)

where:

n_expression
Any expression that evaluates to a numerical value.
n_expression
Any positive integer. Represents the top number of rankings displayed in the result set, 1 being the highest rank.

A query can contain only one TOPN expression.

The TOPN function resets its values for each group in the query according to the rules outlined in Display Function Reset Behavior.


 Siebel Analytics Server Administration Guide
 Published: 11 March 2004