invantive documentation
Invantive Support ForumsLog In / Sign Up

Product Aggregate Function

Syntax

%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart LR
    x_0_0[PRODUCT]:::quoted --> x_0_1["("]:::quoted
    x_0_1 --> x_0_2[DISTINCT]:::quoted
    x_0_1 --> x_0_2a[ALL]:::quoted
    x_0_2a --> x_0_3
    x_0_1 --> x_0_3
    x_0_2 --> x_0_3[<a href="Invantive UniversalSQL/Grammar/Expression" class="internal-link">expression</a>]
    x_0_3 --> x_0_4[")"]:::quoted

Purpose

Group function to multiply together individual numerical values. Multiplying large values can quickly exceed the range of the resulting decimal data type. The product group function is typically used in financial and probability calculations with values near 1. Occurrences of null are ignored; when solely null values are present, the outcome is 1. With ALL, the default, every value counts as often as it occurs; ALL is accepted from release 28.0.

Examples

The following example calculates the cumulative price indexation over the yearly indexation factors of the customer contracts:

select product(idx.factor)
from   csvtable
       ( passing 'Acme Industries#2024#1.02|Acme Industries#2025#1.03|Carlson Ltd#2024#1.05'
         row delimiter '|'
         column delimiter '#'
         columns customer_name varchar2 position next
         ,       year          number   position next
         ,       factor        number   position next
       ) idx

-------------------
1.10313

The following example calculates per customer the cumulative indexation factor to apply to the original contract price:

select idx.customer_name
,      product(idx.factor)
from   csvtable
       ( passing 'Acme Industries#2024#1.02|Acme Industries#2025#1.03|Carlson Ltd#2024#1.05'
         row delimiter '|'
         column delimiter '#'
         columns customer_name varchar2 position next
         ,       year          number   position next
         ,       factor        number   position next
       ) idx
group
by     idx.customer_name
order
by     idx.customer_name

-------------------
Acme Industries    1.0506
Carlson Ltd        1.05