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

Stddev集計 Function (*.fnc)

構文

%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart TD
    stdDevAggregateFunction_start((START))
    stdDevAggregateFunction_start --> stdDevAggregateFunction_0_0[STDDEV]:::quoted
    stdDevAggregateFunction_0_0 --> stdDevAggregateFunction_0_1["("]:::quoted
    stdDevAggregateFunction_0_1 --> stdDevAggregateFunction_0_2[DISTINCT]:::quoted
    stdDevAggregateFunction_0_1 --> stdDevAggregateFunction_0_2a[ALL]:::quoted
    stdDevAggregateFunction_0_2a --> stdDevAggregateFunction_0_3
    stdDevAggregateFunction_0_2 --> stdDevAggregateFunction_0_3[<a href="Invantive UniversalSQL/Grammar/Expression" class="internal-link">expression</a>]
    stdDevAggregateFunction_0_3 --> stdDevAggregateFunction_0_4[")"]:::quoted
    stdDevAggregateFunction_0_4 --> stdDevAggregateFunction_end((END))

目的

グループ内の数値の集合から標準偏差を求めるグループ関数です。 母集団の標準偏差を計算します。平均からの偏差の二乗の合計を値の数で割ります。 値が1つだけのグループの結果は 0 です。 DISTINCT を指定すると、一意の各値は1回だけ含まれます。 ALL(既定値)を指定すると、各値は出現した回数分だけ計上されます。ALLはリリース28.0から使用できます。

例

次の例では、Wholesale顧客の未払残高の標準偏差を計算します。たとえば、セグメント内で信用リスクがどの程度均等に分散しているかを判断するためです:

select stddev(cus.balance)
from   csvtable
       ( passing 'Acme Industries#Manufacturing#12500#50000|Bergmann GmbH#Manufacturing#0#25000|Carlson Ltd#Wholesale#2500#10000|Dubois SA#Wholesale#7500#10000|Everest BV#Services##5000'
         row delimiter '|'
         column delimiter '#'
         columns name         varchar2 position next
         ,       segment      varchar2 position next
         ,       balance      number   position next
         ,       credit_limit number   position next
       ) cus
where  cus.segment = 'Wholesale'

-------------------
2500

次の例では、残高のない顧客を除外して、顧客セグメントごとの未払残高の標準偏差を計算します:

select cus.segment
,      stddev(cus.balance)
from   csvtable
       ( passing 'Acme Industries#Manufacturing#12500#50000|Bergmann GmbH#Manufacturing#0#25000|Carlson Ltd#Wholesale#2500#10000|Dubois SA#Wholesale#7500#10000|Everest BV#Services##5000'
         row delimiter '|'
         column delimiter '#'
         columns name         varchar2 position next
         ,       segment      varchar2 position next
         ,       balance      number   position next
         ,       credit_limit number   position next
       ) cus
where  cus.balance is not null
group
by     cus.segment
order
by     cus.segment

-------------------
Manufacturing    6250
Wholesale        2500