This function is intended to be used as part an aggregation to return any single value. When run at scale, there is some randomness to the value that is returned from the aggregated groupings, although randomness in not guaranteed.
In a flat aggregation, in which no aggregate function is applied, it selects the first value that it can retrieve from a column, which is the first value. This function has limited value outside of an aggregation. See Pivot Transform.
Input column might be of Integer, Decimal, String, Object, or Array type.
pivot value:ANY(myRating) group:postal_code limit: 1
Output: Generates a two-column table containing the unique values from the
postal_code column and a single value from the
myRating column for the
postal_code value. The
limit parameter defines the maximum number of output columns.
pivot value:ANY(function_col_ref) [group:group_col_ref] [limit:limit_count]
|function_col_ref||Y||string||Name of column to which to apply the function|
For more information on syntax standards, see Language Documentation Syntax Notes.
For more information on the
limit parameters, see Pivot Transform.
Name of the column from which to extract a value based on the grouping.
- Literal values are not supported as inputs.
- Multiple columns and wildcards are not supported.
|Required?||Data Type||Example Value|
|Yes||String (column reference)|
Example - Aggregating on one customer per month
You want to do some sampling of customer orders on a monthly basis. For your sample, you want to select the sum of orders for one customer each month.
Here are the orders for 1Q 2015:
To aggregate this date by month, you must extract the month value from the
derive type:single value: DATEFORMAT(Date, 'MMM') as:'month_Date'
You should now have a new column with three-letter month abbreviations. You can use the following aggregation to gather the sum of one customer's orders for each month:
pivot value: ANY(CustId),SUM(Qty) group: month_Date limit:1