Aggregation operators

You can use aggregation operators over a collection of objects. Aggregation operators calculate the average, total, minimum, or maximum value of the numeric attributes in a collection of objects, or the number of objects in a collection.

Aggregation operators compute a value from a collection of values.

You cannot use aggregation operators in the action part of the rule.

Table 1. Aggregation operators
Operator Description Example

the average <attribute> of <collection>

Calculates the average value of an attribute in the collection of objects.

if 
the average amount of all purchases is more than 500
then 
 print "Gold customer."

the minimum <attribute> of <collection>

Returns the minimum value of an attribute in the collection of objects.

if 
 the minimum amount of all purchases is at least 200
then 
 print "eligible for loyalty card"; 

the maximum <attribute> of <collection>

Returns the maximum value of an attribute in the collection of objects.

if 
 the maximum amount of all purchases is between 800 and 1000
then 
 print "send 20% discount voucher"; 

the total <attribute> of <collection>

Calculates the total value of an attribute in the collection of objects.

if 
 the total amount of all purchases is more than 1000
then 
 print "too much spending."; 

the number of <collection>

Returns the number of objects in a collection.

When this operator is applied to a collection that is defined by the all construct, the article is removed to improve readability.

if 
 the number of purchases is more than 100
then 
 print "send 25% discount voucher"; 

Example

if 
    the total amount of all purchase events,
        where the time of each purchase is during the last period of 1 week, is more than 1000
then 
    print "too much spending in 7 consecutive days.";