Example: Aggregate and Ordered Analytic Function Usage - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

The first recursive view definition demonstrates the valid use of an ordered analytic function, which is bold. 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 bold. 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;