17.10 - Example: MIN and MAX Aggregations in a Sequenced Query - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - Temporal Table Support

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

MIN and MAX functions can be used in sequenced aggregations with temporal tables, however it is important to apply them to appropriate columns. For the aircraft service example, the information in the Charge column is not a state value. Applying MIN and MAX to this column in a time dependent sequenced aggregation would give results that are easily misinterpreted or not meaningful.

However, it would be meaningful to ask for the minimum and maximum number of workers assigned to all jobs combined at any time:

SEQUENCED VALIDTIME
SELECT id,
       min(NumWorkersAssigned) as Minworkers,
       max(NumWorkersAssigned) as Maxworkers
FROM aircraft_service
GROUP BY 1
ORDER BY VALIDTIME;
ID Minworkers Maxworkers VALIDTIME
123 5 5 ('11/01/04', '11/01/05')
123 3 5 ('11/01/05', '11/01/06')
123 1 5 ('11/01/06', '11/01/07')
123 1 5 ('11/01/07', '11/01/08')
123 1 1 ('11/01/08', '11/01/09')