TD_SMOOTHMA Function Examples | Teradata Vantage - TD_SMOOTHMA Examples - Teradata Vantage

Database Unbounded Array Framework Time Series Functions

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-10-04
dita:mapPath
ncd1634149624743.ditamap
dita:ditavalPath
ruu1634160136230.ditaval
dita:id
ncd1634149624743

Example: TD_SMOOTHMA Call with One Payload, WELL_KNOWN

EXECUTE FUNCTION INTO VOLATILE ART (MA_RES)
  TD_SMOOTHMA (
    SERIES_SPEC (
      TABLE_NAME (Orders1_12),
      SERIES_ID (OrderID),
      ROW_AXIS (SEQUENCE (SEQ)),
      PAYLOAD (FIELDS (Qty1), CONTENT (REAL))
    ),
    FUNC_PARAMS (
      WINDOW (5),
      PAD (4.5555),
      MA (MEAN),
      WELL_KNOWN ("5MA")
    )
  );

TD_SMOOTHMA Result

Display the primary RETURNS TABLE with this statement:

SELECT * FROM MA_RES;
OrderID  ROW_I  MAGNITUDE_Qty1
  123      0    4.55550000000000E 000
  123      1    4.55550000000000E 000
  123      2    4.20000000000000E 000
  123      3    4.80000000000000E 000
  123      4    4.40000000000000E 000
  123      5    4.20000000000000E 000
  123      6    4.40000000000000E 000
  123      7    4.00000000000000E 000
  123      8    4.20000000000000E 000
  123      9    4.80000000000000E 000
  123      10   4.55550000000000E 000
  123      11   4.55550000000000E 000

Example: TD_SMOOTHMA Call with One Payload, WEIGHTS

EXECUTE FUNCTION INTO VOLATILE ART (MA_RES)
  TD_SMOOTHMA (
    SERIES_SPEC (
      TABLE_NAME (Orders1_12),
      SERIES_ID (OrderID),
      ROW_AXIS (SEQUENCE (SEQ)),
      PAYLOAD (FIELDS (Qty1), CONTENT (REAL))
    ),
    FUNC_PARAMS (
      MA (MEAN),
      WEIGHTS (10, 15, 25, 25, 15, 10)
    )
  );

TD_SMOOTHMA Result

Display the primary RETURNS TABLE with this statement:

SELECT * FROM MA_RES;
OrderID  ROW_I  MAGNITUDE_Qty1
  123      0    4.52500000000000E 000
  123      1    4.57500000000000E 000
  123      2    4.35000000000000E 000
  123      3    4.80000000000000E 000
  123      4    4.07500000000000E 000
  123      5    4.35000000000000E 000

Example: TD_SMOOTHMA Call with Two Payloads, ONE_SIDED, FLOW_THROUGH

EXECUTE FUNCTION INTO VOLATILE ART (MA_RES)
  TD_SMOOTHMA (
    SERIES_SPEC (
      TABLE_NAME (Orders1_12mf),
      SERIES_ID (OrderID),
      ROW_AXIS (SEQUENCE (SEQ)),
      PAYLOAD (FIELDS (Qty1, Qty2), CONTENT (MULTIVAR_REAL))
    ),
    FUNC_PARAMS (
      WINDOW (5),
      MA (MEAN),
      ONE_SIDED (1)
    ),
    OUTPUT_FMT (INDEX_STYLE (FLOW_THROUGH))
  );

TD_SMOOTHMA Result

Display the primary RETURNS TABLE with this statement:

SELECT * FROM MA_RES;
OrderID     ROW_I       Qty1                   Qty2
----------- ----------- ---------------------- ----------------------
123         15          4.20000000000000E 000 4.80000000000000E 000
123         16          4.80000000000000E 000 4.40000000000000E 000
123         17          4.40000000000000E 000 4.20000000000000E 000
123         18          4.20000000000000E 000 4.60000000000000E 000
123         19          4.40000000000000E 000 4.20000000000000E 000
123         20          4.00000000000000E 000 4.40000000000000E 000
123         21          4.20000000000000E 000 5.00000000000000E 000
123         22          4.80000000000000E 000 4.60000000000000E 000
223         15          4.20000000000000E 000 4.80000000000000E 000
223         16          4.80000000000000E 000 4.40000000000000E 000
223         17          4.40000000000000E 000 4.20000000000000E 000
223         18          4.20000000000000E 000 4.60000000000000E 000
223         19          4.40000000000000E 000 4.20000000000000E 000
223         20          4.00000000000000E 000 4.40000000000000E 000
223         21          4.20000000000000E 000 5.00000000000000E 000
223         22          4.80000000000000E 000 4.60000000000000E 000