ANSI SQL Functions

Interactive Reporting supports ANSI SQL functions, and windowing clauses for the data. Windowing or partions refers to a fixed window or "sub-range" over which the aggregate function is computed for each row in the partition.

The windowing clauses include:

For example, if you want to compute the three-month moving average sales for each store in the sales_fact table, then partition by StoreID, order by Month, and perform the computation over the current row and the two preceding rows as shown below:

SELECT StoreID, Sales_Month, ProductID, Sales, AVG(Sales) OVER (PARTITION BY StoreID ORDER BY Sales_Month ROWS BETWEEN 2 PRECEDING AND CURRENT ROW)

  To apply an ANSI SQL function:

  1. Drag an topic from the Elements Table Catalog to the Content pane.

  2. Drag a topic to the Request line.

  3. Select the topic item on the Request line and on the shortcut menu, select Add Computed Item.

    The Modify Item dialog box is displayed.

  4. Select Functions.

    The Functions dialog box is displayed.

    Note:

    If a function does not support windowing clauses, the Function dialog box shows only a Parameters tab. If windowing clauses are supported by the currently selected function, an Advanced tab is available for you to build windowing clauses.

  5. Select a function from the Function Categories list.

    A list of supported ANSI functions is shown in the Function list. Database specific ANSI functions are also shown.

  6. In the Partition by field, select a topic item by which to partition data.

    To review and select from a list of topic items, click Reference and select an item from the Reference dialog box.

  7. In the Ordered by field, select the topic item by which to sort.

    To review and select from a list of topic items, click Reference and select an item from the Reference dialog box.

  8. Select to sort in Ascending or Descending order.

  9. In the Rows fields, specify the number of rows over which the aggregate function is computed for each row in the partition.

    To select all values, leave the default value as “Unbounded”.

  10. Select the partition parameters for the Rows values. That is, select the capture area for the partition. Valid options are

    • Preceding

    • Current Row

  11. To select values between the rows selected in the Row field, specify which rows and indicate the partition parameter. Valid options are:

    • Current Row

    • Following

  12. Select OK.

Table 142. ANSI SQL Functions

NameDescriptionReturn TypeParameters
CORRReturns the Pearson product moment correlation coefficient of its argument fall all non-null data point pairs.Realnumeric column expressions x and y
COVAR_POPReturns the population covariance of its arguments for all non-null data point pairs.Realnumeric column expressions x and y
COVAR_SAMPReturns the sample covariance of its arguments for all non-null pairs.Realnumeric column expression x and y
GROUPINGReturns a value that indicates whether a specified column in the result row was excludeIntegeran item of a GROUP BY clause
KURTOSISReturns the distribution kurtosis of the column expression.Realnumeric column expression
REGR_AVGXReturns the mean of the independent_column_expression for all non-null data pairs of the dependent and independent variable arguments.Realdependent and independent column expressions
REGR_AVGYReturns the mean of the dependent_column_expression for all non-null data pairs of the dependent and independent variable arguments.Realdependent and independent column expressions
REGR_COUNTReturns the count of all non-null data pairs of the dependent and independent variable arguments.Realdependent and independent column expressions
REGR_INTERCEPTReturns the intercept of the univariate linear regression line through all non-null data pairs of the dependent and independent variable arguments.Realdependent and independent column expressions
REGR_R2Returns the coefficient of determination for all non-null data pairs of the dependent and independent variable arguments.Realdependent and independent column expressions
REGR_SLOPEReturns the slope of the univariate linear regression line through all non-null data pairs of the dependent and independent variable arguments.Realdependent and independent column expressions
REGR_SXXReturns the sum of the squares of the independent_column_expression for all non-null data pairs of the dependent and independent variable arguments.Realdependent and independent column expressions
REGR_SXYReturns the sum of the products of the independent_column_expression and the dependent_column_expression for all non-null data pairs of the dependent and independent variable arguments.Realdependent and independent column expressions
REGR_SYYReturns the sum of the squares of the dependent_column_expression for all non-null data pairs of the dependent and independent variable arguments.Realdependent and independent column expressions
SKEWReturns the skewness of the distribution of value_expression.Realnumeric column expression
STDDEV_SAMPReturns the sample standard deviation for the non-null data points in value_expression.Realnumeric column expression
VAR_POPReturns the population variance for the data points in value_expression.Realnumeric column expression
VAR_SAMPReturns the sample variance for the data points in value_expression.Realnumeric column expression
WIDTH_BUCKETReturns the number of the partition to which value_expression is assigned.Integervalue expression, lower bound, upper bound, partition count
PERCENT_RANKReturns the relative rank of rows for a value_expression.Real 
ROW_NUMBERReturns the sequential row number, where the first row is number one, of the row within its window partition according to the window ordering of the window.Integer 
POSITIONReturns the position in string_expression_2 where string_expression_1 starts.IntegerString expression 1, string expression 2
TRANSLATEConverts a character string or character string expression from one server character set to another server character set.StringString expression, conversion
CHARACTER_LENGTHReturns the length of a string either in logical characters or in bytes.IntegerString expression
OCTET_LENGTHReturns the length of string_expression in octets.IntegerString expression
CURRENT_DATEReturns the current system date.Date 
CURRENT_TIMEReturns the current system time.Time 
CURRENT_TIMESTAMPReturns the current system timestamp.Timestamp 

An Oracle database loads these functions:

Function   
SumAbsSinRpad
MinFloorCosSubstr
MaxPowerTanTo_char
AvgRoundDecodeLast_day
CountSign NvlSysdate
Add MonthsSqrtCeilMonths_between
ConcatLowerStddevNext_day
LengthUpperVariance 
TruncAsciiInitcap 
UserExpLpad 

A DB2 database loads these functions:

Function      
SumLowerCoalesceMicrosecondDecimalConcatRight
MinUpperCurrent DateMinuteDigitsHexSoundex
MaxAsciiCurrent TimeMonthIntegerInsertSubstr
AvgExpDateMonthnameLog10LcaseUcase
CountLTrimDayQuarterModLeft 
AbsRTrimDaynameSecondRandLength 
FloorSinDayOfWeekTimeSmallintLocate 
PowerCosDayofyearWeekTruncPosstr 
RoundTanDaysYearCharRepeat 
SqrtNullifHourCeilChrReplace 

A SQL: (MSSQL) database loads these functions:

Function   
SumSqrtGroupingRight
MinLowerWidth_BucketSubstring
MaxUpperRow_NumberStr
AvgAsciiCurrent_TimestampUser_name
CountExpRankSuser_name
AbsLTrimLengthDateadd
FloorRTrimIsnullDatediff
PowerSinCeilingDatename
RoundCosRandDatepart
SignTanReverseGetdate