prod

The prod aggregate calculates the cumulative product of a group of values.

Synopsis

AFL% aggregate(array,prod(attribute)[,dimension_1,dimension_2,...])
AQL% SELECT prod(attribute) FROM array [GROUP BY dimension_1,dimension_2,...]

Summary

The prod aggregate calculates the cumulative product of a group of values. The product of an empty set is 0. The product of a set that contains only NULL values is also 1. If the set contains NULL and NOT NULL values, the result is the product of all the NOT NULL values.

Example

To find the product of every column of a 3×3 array, do the following:

  1. Create and array, m3x3, and store values of 1–9 into it:

    AFL% store(build(<val:double>[row=0:2; col=0:2],row*3+col+1),m3x3);


    The output is:

    {row,col} val
    {0,0} 1
    {0,1} 2
    {0,2} 3
    {1,0} 4
    {1,1} 5
    {1,2} 6
    {2,0} 7
    {2,1} 8
    {2,2} 9
  2. Find the product of each column in m3x3:

    AFL% aggregate(m3x3,prod(val),col) 


    The output is:

    {col} val_prod
    {0} 28
    {1} 80
    {2} 162
  3. Find the product of all the cells of m3x3:

    AFL% aggregate(m3x3,prod(val)) 


    The output is:

    {i} val_prod
    {0} 362880
  4. The array can be removed now.

    remove(m3x3);


    The output is:

    Query was executed successfully