nPath Function Results Example | Teradata Vantage - nPath Results Example: FIRST, Three Forms of ACCUMULATE, COUNT, and NTH - Teradata® Database

Database Analytic Functions

Product
Teradata® Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-28
dita:mapPath
Teradata_Vantage™___Advanced_SQL_Engine_Analytic_Functions.withLogo_upload_July2021/wnd1589838592459.ditamap
dita:ditavalPath
Teradata_Vantage™___Advanced_SQL_Engine_Analytic_Functions.withLogo_upload_July2021/ayr1485454803741.ditaval
dita:id
B035-1206
lifecycle
previous
Product Category
Teradata Vantage™

Input

The input table for this example is clicks, as in nPath Results Example: FIRST and Three Forms of ACCUMULATE.

SQL Call

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;

Output

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