彙總函式 aggregation-functions
彙總函式會針對一組值執行計算,並傳回單一摘要結果。 這些函式可讓您透過計算平均值、尋找最小值和最大值、計數元素以及加總數值,來分析歷程運算式中的資料。
當您需要以下動作時,請使用彙總函式:
- 從清單或陣列計算統計值(avg,sum,min,max)
- 集合中的計數元素(count, countOnlyNull, countWithNull),包含或排除null值的選項
- 決定資料集內的唯一值(distinctCount, distinctCountWithNull)
- 根據計算量度做出資料導向式決策
彙總函式會根據其特定行為自動處理null值,讓處理可能包含遺失或未定義值的真實資料更容易。
avg avg
傳回一組運算式中的平均值(以清單或兩個運算式形式提供)。 會忽略Null值。
avg(<parameter>)支援的型別:
- listInteger
- listDecimal
- 小數
- 整數
avg(<listInteger>)
avg(<listDecimal>)
avg(<decimal>,<decimal>)
avg(<decimal>,<integer>)
avg(<integer>,<decimal>)
avg(<integer>,<integer>)
傳回小數。
avg(@event{BarBeacon.inventory},5)
avg([10,3,8])
傳回7.0。
avg(10.2, 3)
傳回6.6。
計數 count
計算清單的元素而不考慮null值。
count(<listAny>)
count(<listObject>)
| table 0-row-3 1-row-3 | ||
|---|---|---|
| 參數 | 類型 | 說明 |
| listToProcess | listString、listBoolean、listInteger、listDecimal、listDuration、listDateTime、listDateTimeOnly、listDateOnly或listObject | 要處理的清單。 對於listObject,它必須是欄位參考。 listObject不能包含null物件。 |
count(<listAny>)
傳回整數。
count([10,2,10,null])
傳回3。
count(@event{my_event.productListItems})
傳回給定物件陣列(listObject型別)中的物件數目。 備註:listObject不能包含null物件
countOnlyNull countOnlyNull
計算清單中Null值的數量。
countOnlyNull(<listAny>)| table 0-row-2 1-row-2 | |
|---|---|
| 參數 | 類型 |
| listToProcess | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly |
countOnlyNull(<listAny>)
傳回整數。
countOnlyNull([10,2,10,null])
傳回1。
注意:此函式不支援引數<listObject>。
countWithNull countWithNull
計算清單的所有元素,包括null值。
countWithNull(<listAny>)| table 0-row-2 1-row-2 | |
|---|---|
| 參數 | 類型 |
| listToProcess | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly |
countWithNull(<listAny>)
傳回整數。
countWithNull([10,2,10,null])
傳回4。
注意:此函式不支援引數<listObject>。
distinctCount distinctCount
計算不同值的數目,忽略null值。
distinctCount(<listAny>)| table 0-row-3 1-row-3 2-row-3 | ||
|---|---|---|
| 參數 | 類型 | 說明 |
| listToProcess | listString、listBoolean、listInteger、listDecimal、listDuration、listDateTime、listDateTimeOnly、listDateOnly或listObject | 要處理的清單。 對於listObject,它必須是欄位參考。 |
| keyAttributeName | 字串 | 此引數是選用專案,且僅適用於listObject。 如果未提供引數,如果所有屬性的值都相同,則會將物件視為重複。 否則,如果給定的屬性具有相同的值,則會將物件視為重複。 |
distinctCount(<listAny>)
傳回整數。
distinctCount(<listObject>)
distinctCount(<listObject>,<string>)
傳回物件清單。
distinctCount([10,2,10,null])
傳回2。
distinctCount(@event{my_event.productListItems})
傳回給定物件陣列(listObject型別)中完全不同的物件數目。
distinctCount(@event{my_event.productListItems}, "SKU")
傳回具有不同「SKU」屬性值{}的物件數目。
distinctCountWithNull distinctCountWithNull
計算不同值的數量,包括null值。
distinctCountWithNull(<listAny>)| table 0-row-2 1-row-2 | |
|---|---|
| 參數 | 類型 |
| listToProcess | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly |
distinctCountWithNull(<listAny>)
傳回整數。
distinctCountWithNull([10,2,10,null])
傳回3。
注意:此函式不支援引數<listObject>。
max max
傳回一組運算式中的最大值,以清單或兩個運算式形式提供。 會忽略Null值。
max(<parameter>)- listDuration
- listInteger
- listDecimal
- listDateTime
- listDateTimeOnly
- listDateOnly
- 期間
- 整數
- 小數
- dateTime
- dateTimeOnly
max(<listDuration>)
傳回持續時間。
max(<listInteger>)
傳回持續時間。
max(<listDateTimeOnly>)
傳回日期時間,不考慮時區。
max(<listDateTime>)
傳回日期時間。
max(<listDateOnly>)
傳回日期。
max(<listDecimal>)
傳回小數。
max(<decimal>,<decimal>)
傳回小數。
max(<duration>,<duration>)
傳回持續時間。
max(<dateTime>,<dateTime>)
傳回日期時間。
max(<dateTimeOnly>,<dateTimeOnly>)
傳回日期時間,不考慮時區。
max(<integer>,<integer>)
傳回整數。
max(@event{BarBeacon.inventory},5)
max([10,3,8])
傳回10。
max([10,null,8])
傳回10。
min min
傳回一組運算式中的最小值,以清單或兩個運算式形式提供。 會忽略Null值。
min(<parameters>)- listDuration
- listInteger
- listDecimal
- listDateTime
- listDateTimeOnly
- listDateOnly
- 期間
- 整數
- 小數
- dateTime
- dateTimeOnly
min(<listDuration>)
傳回持續時間。
min(<listInteger>)
傳回持續時間。
min(<listDateTimeOnly>)
傳回日期時間,不考慮時區。
min(<listDateTime>)
傳回日期時間。
min(<listDateOnly>)
傳回日期。
min(<listDecimal>)
傳回小數。
min(<decimal>,<decimal>)
傳回小數。
min(<duration>,<duration>)
傳回持續時間。
min(<dateTime>,<dateTime>)
傳回日期時間。
min(<dateTimeOnly>,<dateTimeOnly>)
傳回日期時間,不考慮時區。
min(<integer>,<integer>)
傳回整數。
min(@event{BarBeacon.inventory},5)
min([10,3,8])
傳回3。
min([10,null,8])
傳回8。
sum sum
傳回一組運算式的值總和。 會忽略Null值。
sum(<parameters>)- listInteger
- listDecimal
- 期間
- 整數
- 小數
sum(<listDecimal>)
傳回小數。
sum(<listInteger>)
傳回整數。
sum(<integer>,<integer>)
傳回整數。
sum(<decimal>,<decimal>)
傳回小數。
sum(@event{BarBeacon.inventory},5)
sum([10,3,8])
傳回21。
sum([10.5,null,8.1])
傳回18.6。
This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.
For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.
- TL;DR: This page documents all aggregation functions available in AJO journey expressions, covering how to compute averages, sums, min/max values, counts, and distinct counts over lists and arrays.
Intents:
- Calculate the average of a list of numeric values using
avg - Sum numeric values in a list or from event fields using
sum - Find the minimum or maximum value in a list using
minormax - Count non-null, null-only, or all elements in a list using
count,countOnlyNull, orcountWithNull - Count distinct values in a list, with or without nulls, using
distinctCountordistinctCountWithNull - Filter unique objects in a listObject by a specific key attribute using
distinctCountwith a key parameter
Glossary:
- listObject: A list of complex objects (field references); cannot contain null objects (product-specific)
- listAny: A list of any supported scalar type (string, boolean, integer, decimal, duration, dateTime, dateTimeOnly, dateOnly) (product-specific)
- Null value: An absent or undefined element in a list; most aggregation functions ignore nulls unless the function explicitly handles them (e.g.,
countOnlyNull,countWithNull,distinctCountWithNull)
Guardrails:
countOnlyNull,countWithNull, anddistinctCountWithNulldo not support the<listObject>parameter typedistinctCounton alistObjectrequires the list to be a field reference, not an inline literalcounton alistObjectrequires the list to be a field reference; a listObject cannot contain null objects
Terminology:
- Canonical name: Aggregation functions — Acronym: none — variants: aggregate functions, collection functions
- Synonyms: “count” = “count non-null elements”; “countWithNull” = “count all elements including nulls”
- Do not confuse: “distinctCount” (ignores nulls) ≠ “distinctCountWithNull” (includes nulls as a distinct value)
FAQ:
- Q: Does
avginclude null values in its calculation? — No,avgignores null values automatically. - Q: What is the difference between
countandcountWithNull? —countexcludes null values from the total, whilecountWithNullcounts every element including nulls. - Q: Can I use
countOnlyNullon a listObject? — No,<listObject>is not supported bycountOnlyNull,countWithNull, ordistinctCountWithNull. - Q: How do I count distinct objects in an array based on a specific attribute? — Use
distinctCount(@event{...}, "attributeName")providing the key attribute name as the second parameter. - Q: What does
maxreturn when the list contains nulls? —maxignores null values and returns the maximum among the non-null elements.