16.20 - Examples - Teradata Database - Teradata Vantage NewSQL Engine

Teradata Vantageā„¢ Time Series Tables and Operations

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Content Type
Programming Reference
Publication ID
B035-1208-162K
Language
English (United States)
Last Update
2019-05-02

Example: Using TOP Without TIES

/*PTI Table*/SELECT $TD_TIMECODE_RANGE, $TD_GROUP_BY_TIME, BUOYID, TOP(2, TEMPERATURE)
FROM OCEAN_BUOYS
WHERE TD_TIMECODE BETWEEN TIMESTAMP '2014-01-06 10:00:00' AND TIMESTAMP '2014-01-06 10:06:00' AND BUOYID=44
GROUP BY TIME (MINUTES(2) AND BUOYID) FILL(NULLS)
ORDER BY 1, 4, 3;

/*Non-PTI Table*/
SELECT $TD_TIMECODE_RANGE, $TD_GROUP_BY_TIME, BUOYID, TOP(2, TEMPERATURE)
FROM OCEAN_BUOYS_NONPTI
WHERE TIMECODE BETWEEN TIMESTAMP '2014-01-06 10:00:00' AND TIMESTAMP '2014-01-06 10:06:00' AND BUOYID=44
GROUP BY TIME (MINUTES(2) AND BUOYID)
USING TIMECODE(TIMECODE)
FILL(NULLS)
ORDER BY 1, 4, 3;

The results are the same for both tables:

TIMECODE_RANGE GROUP BY TIME (MINUTES(10)) BUOYID TEMPERATURE
('2014-01-06 10:00:00.000000+00:00', '2014-01-06 10:02:00.000000+00:00') 1 44 ?
('2014-01-06 10:00:00.000000+00:00', '2014-01-06 10:02:00.000000+00:00') 1 44 ?
('2014-01-06 10:00:00.000000+00:00', '2014-01-06 10:02:00.000000+00:00') 1 44 53
('2014-01-06 10:00:00.000000+00:00', '2014-01-06 10:02:00.000000+00:00') 1 44 54
('2014-01-06 10:02:00.000000+00:00', '2014-01-06 10:04:00.000000+00:00') 2 44 ?
('2014-01-06 10:02:00.000000+00:00', '2014-01-06 10:04:00.000000+00:00') 2 44 ?
('2014-01-06 10:02:00.000000+00:00', '2014-01-06 10:04:00.000000+00:00') 2 44 55
('2014-01-06 10:02:00.000000+00:00', '2014-01-06 10:04:00.000000+00:00') 2 44 56
('2014-01-06 10:04:00.000000+00:00', '2014-01-06 10:06:00.000000+00:00') 3 44 ?
('2014-01-06 10:04:00.000000+00:00', '2014-01-06 10:06:00.000000+00:00') 3 44 ?
('2014-01-06 10:04:00.000000+00:00', '2014-01-06 10:06:00.000000+00:00') 3 44 ?
('2014-01-06 10:04:00.000000+00:00', '2014-01-06 10:06:00.000000+00:00') 3 44 ?

Example: Using TOP With TIES

/*PTI Table*/
SELECT $TD_TIMECODE_RANGE, $TD_GROUP_BY_TIME, BUOYID, TOP WITH TIES(2, TEMPERATURE)
FROM OCEAN_BUOYS
WHERE TD_TIMECODE BETWEEN TIMESTAMP '2014-01-06 10:00:00' AND TIMESTAMP '2014-01-06 10:06:00' AND BUOYID=44
GROUP BY TIME (MINUTES(2) AND BUOYID) FILL(NULLS)
ORDER BY 1, 4, 3;

/*Non-PTI Table*/
SELECT $TD_TIMECODE_RANGE, $TD_GROUP_BY_TIME, BUOYID, TOP WITH TIES(2, TEMPERATURE)
FROM OCEAN_BUOYS_NONPTI
WHERE TIMECODE BETWEEN TIMESTAMP '2014-01-06 10:00:00' AND TIMESTAMP '2014-01-06 10:06:00' AND BUOYID=44
GROUP BY TIME (MINUTES(2) AND BUOYID)
USING TIMECODE(TIMECODE)
FILL(NULLS)
ORDER BY 1, 4, 3;

The results are the same for both tables:

TIMECODE_RANGE GROUP BY TIME (MINUTES(10)) BUOYID TEMPERATURE
('2014-01-06 10:00:00.000000+00:00', '2014-01-06 10:02:00.000000+00:00') 1 44 53
('2014-01-06 10:00:00.000000+00:00', '2014-01-06 10:02:00.000000+00:00') 1 44 54
('2014-01-06 10:02:00.000000+00:00', '2014-01-06 10:04:00.000000+00:00') 2 44 55
('2014-01-06 10:02:00.000000+00:00', '2014-01-06 10:04:00.000000+00:00') 2 44 56
('2014-01-06 10:04:00.000000+00:00', '2014-01-06 10:06:00.000000+00:00') 3 44 ?
('2014-01-06 10:04:00.000000+00:00', '2014-01-06 10:06:00.000000+00:00') 3 44 ?