例: 集約および順序付き分析関数の使い方 - Teradata Database - Teradata Vantage NewSQL Engine - 例: 集約および順序付き分析関数の使い方、CREATE REPLACE RECURSIVE VIEW文

Teradata Vantage™ SQLデータ定義言語 構文規則および例

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
2019年3月
Language
日本語
Last Update
2019-10-29
dita:mapPath
ja-JP/wkf1512081455740.ditamap
dita:ditavalPath
ja-JP/wkf1512081455740.ditaval
dita:id
B035-1144
Product Category
Software
Teradata Vantage

最初の再帰的ビュー定義は、順序付き分析関数の有効な使用法を示しており、その部分は太字で強調されています。この使い方が有効なのは、それが定義の繰り返し文ではなくシード文の中にあるからです。

    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);

2番目の再帰的ビュー定義は、同じ順序付き分析関数の無効な使用法を示しており、その部分はここでも太字で強調されています。この使い方が無効なのは、それが定義のシード文ではなく繰り返し文の中にあるからです。

    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;