InvantiveのドキュメントInvantive Cloudの一部
Invantive サポートフォーラムログイン / 会員登録

Product Aggregate Function (*.fnc)

構文

%%{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

目的

数値の個別の値を掛け合わせるグループ関数です。 大きな値を掛け合わせると、結果がdecimalデータ型の範囲をすぐに超えることがあります。 積のグループ関数は、通常、1付近の値を用いる金融計算や確率計算で使用されます。 nullの出現は無視されます。nullの値のみが存在する場合、結果は1になります。 ALL(既定値)を指定すると、各値は出現した回数分だけ計上されます。ALLはリリース28.0から使用できます。

例

次の例では、顧客契約の年次インデックス係数に基づいて、累積価格インデックスを計算します。

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

次の例では、顧客ごとに、元の契約価格に適用する累積インデックス係数を計算します。

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