彙總函式 aggregation-functions

彙總函式會針對一組值執行計算,並傳回單一摘要結果。 這些函式可讓您透過計算平均值、尋找最小值和最大值、計數元素以及加總數值,來分析歷程運算式中的資料。

當您需要以下動作時,請使用彙總函式:

彙總函式會根據其特定行為自動處理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。

AI Knowledge Reference

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 min or max
  • Count non-null, null-only, or all elements in a list using count, countOnlyNull, or countWithNull
  • Count distinct values in a list, with or without nulls, using distinctCount or distinctCountWithNull
  • Filter unique objects in a listObject by a specific key attribute using distinctCount with 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, and distinctCountWithNull do not support the <listObject> parameter type
  • distinctCount on a listObject requires the list to be a field reference, not an inline literal
  • count on a listObject requires 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 avg include null values in its calculation? — No, avg ignores null values automatically.
  • Q: What is the difference between count and countWithNull?count excludes null values from the total, while countWithNull counts every element including nulls.
  • Q: Can I use countOnlyNull on a listObject? — No, <listObject> is not supported by countOnlyNull, countWithNull, or distinctCountWithNull.
  • 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 max return when the list contains nulls?max ignores null values and returns the maximum among the non-null elements.
recommendation-more-help
journey-optimizer-help