nPath Range-Matching Example | Teradata Vantage - 17.05 - nPath Range-Matching Example: Find Data for Sessions That Checked Out 3-6 Products - Teradata Database

Teradata Vantage™ - Advanced SQL Engine Analytic Functions

prodname
Advanced SQL Engine
Teradata Database
vrm_release
17.00
17.05
created_date
June 2020
category
Programming Reference
featnum
B035-1206-170K

Input

The input table is aggregate_clicks, from LAG and LEAD Expressions Example: No Alias for Input Query.

SQL-MapReduce Call

SELECT * FROM nPath (
  ON aggregate_clicks PARTITION BY sessionid ORDER BY clicktime
  USING
  Mode (NONOVERLAPPING)
  Pattern ('H+.D*.C{3,6}.D')
  Symbols (
    pagetype = 'home' AS H,
    pagetype='checkout' AS C,
    pagetype<>'home' AND pagetype<>'checkout' AS D
  )
  Result (
    FIRST (sessionid OF C) AS sessionid,
    max_choose (productprice, productname OF C) AS
    most_expensive_product,
    MAX (productprice OF C) AS max_price,
    min_choose (productprice, productname of C) AS
    least_expensive_product,
    MIN (productprice OF C) AS min_price)
) AS dt ORDER BY dt.sessionid;

Output

sessionid most_expensive_product max_price least_expensive_product min_price
5 cellphones 600 bookcases 150