16.20 - Example: Aggregate and Ordered Analytic Function Usage - Teradata Database - Teradata Vantage NewSQL Engine

Teradata Vantage™ SQL Data Definition Language Syntax and Examples

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2019-05-24
dita:mapPath
wkf1512081455740.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.ditaval

The first recursive view definition demonstrates the valid use of an ordered analytic function, which is highlighted in bold typeface. The usage is valid because it is within the seed statement rather than the recursive statement of the definition.

    CREATE RECURSIVE VIEW reachable_from (source, destination, cost,
                           depth) AS (
      SELECT source, destination,  MSUM(flights.cost, 25,              flights.destination),  0 AS depth
      FROM flights
    UNION ALL
      SELECT in1.source, out1.destination, in1.cost + out1.cost,
             in1.depth + 1
      FROM reachable_from in1, flights AS out1
      WHERE in1.destination = out1.source
      AND   in1.depth <= 100);

The second recursive view definition demonstrates a non-valid use of the same ordered analytic function, which is again highlighted in bold typeface. The usage is not valid because it is within the recursive statement rather than the seed statement of the definition.

    CREATE RECURSIVE VIEW oaf_problem (source, destination, mcost,
                           depth) AS (
      SELECT source, destination, MSUM(cost, 25, destination), 
             0 AS depth
      FROM flights
    UNION ALL
      SELECT in1.source, out1.destination, 
             MSUM(in1.mcost + out1.cost, 25, out1.destination), 
              in1.depth + 1
      FROM oaf_problem AS in1, flights AS out1
      WHERE in1.destination = out1.source
      AND   in1.depth <= 100;