16.20 - nPath Resultの例3: FIRST、3つの形式ACCUMULATE、COUNT、NTH - Teradata Vantage NewSQL Engine

Teradata Vantage™ - NewSQL Engineの分析関数

prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
プログラミング リファレンス
featnum
B035-1206-162K-JPN

入力

この例の入力テーブルは、nPath Resultの例2: FIRSTおよびACCUMULATEの3つの形式 のようにclicksです。

SQL呼び出し

SELECT * FROM nPath (
  ON clicks PARTITION BY sessionid ORDER BY clicktime
  USING
  Mode (NONOVERLAPPING)
  Symbols (
    pagetype='home' AS H,
    pagetype='checkout' AS C,
    pagetype <> 'home' AND pagetype <>'checkout' AS A
  )
  Pattern ('^H+.A*.C+$')
  Result (
    FIRST (sessionid OF ANY (H, A, C)) AS sessionid,
    FIRST (clicktime OF H) AS firsthome,
    FIRST (clicktime OF C) AS firstcheckout,
    ACCUMULATE (productname OF ANY (H,A,C)) AS products_accumulate,
    COUNT (DISTINCT productname OF ANY(H,A,C)) AS count_distinct_products,
    ACCUMULATE (CDISTINCT productname OF ANY (H,A,C)) AS consecutive_distinct_products,
    ACCUMULATE (DISTINCT productname OF ANY (H,A,C)) AS distinct_products,
    NTH (productname, -1 OF ANY(H,A,C)) AS nth
  )
) ORDER BY sessionid;

出力

sessionid firsthome firstcheckout products_accumulate count_distinct_products consecutive_distinct_products distinct_products n
1 06:59:13 07:00:12 [null, null, television, television, envelopes, null] 2 [null, television, envelopes, null] [null, television, envelopes] ?