Counting Preceding Rows in a Sequence - Aster Analytics

Teradata Aster Analytics Foundation User Guide

Product
Aster Analytics
Release Number
6.21
Published
November 2016
Language
English (United States)
Last Update
2018-04-14
dita:mapPath
kiu1466024880662.ditamap
dita:ditavalPath
AA-notempfilter_pdf_output.ditaval
dita:id
B700-1021
lifecycle
previous
Product Category
Software

For each row, this SQL-MapReduce call counts the number of preceding rows in a given sequence (including the current row). The ORDER BY clause specifies DESC because the pattern must be matched over the rows preceding the start row, while the semantics dictate that the pattern be matched over the rows following the start row.

SELECT sessionid, pageid, rank FROM nPath (
  ON clicks1
  PARTITION BY sessionid
  ORDER BY ts DESC
  MODE (OVERLAPPING)
  PATTERN ('A*')
  SYMBOLS (true AS A)
  RESULT (FIRST(sessionid OF A) AS sessionid,
  FIRST (pageid OF A) AS pageid,
  COUNT (* OF A) AS rank)
);