17.10 - Example Query - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)

The queries in this example reference the following table definition and data:

CREATE TABLE t (id INTEGER, v INTEGER);
INSERT INTO t VALUES (1,1);
INSERT INTO t VALUES (1,2);
INSERT INTO t VALUES (1,3);
INSERT INTO t VALUES (1,4);
INSERT INTO t VALUES (1,5);
INSERT INTO t VALUES (1,6);
INSERT INTO t VALUES (1,7);
INSERT INTO t VALUES (1,8);

SELECT id, v, MYSUM(v) OVER
   (PARTITION BY id ORDER BY v) FROM t;

SELECT id, v, MYSUM(v) OVER
   (PARTITION BY id ORDER BY v ROWS UNBOUNDED PRECEDING) FROM t;

SELECT id, v, MYSUM(v) OVER
   (PARTITION BY id ORDER BY v ROWS BETWEEN 2 PRECEDING AND 3 FOLLOWING)
FROM t;

SELECT id, v, MYSUM(v) OVER() FROM t;