Purpose
Returns the newest value, determined by the timecode, for each group. LAST is a single-threaded function.
To invoke the LAST function, use the GROUP BY TIME clause.
Syntax
Syntax Elements
- value_expression
- A literal or column expression to evaluate.
The value_expression cannot be a reference to a view column derived from a function, and cannot contain any ordered analytical or aggregate functions.
Return Values
The return value is the same data type as the input data type.
Nulls are not included in the result computation.
Usage Notes
LAST is only valid on numeric data.
In the event of a tie, such as simultaneous timecode values for a particular group, all tied results are returned. If a sequence number is present with the data, it can break a tie, assuming it is unique across identical timecode values.
Example: Using LAST with Time Series
/*PTI Table*/ SELECT $TD_TIMECODE_RANGE, $TD_GROUP_BY_TIME, BUOYID, LAST(TEMPERATURE) FROM OCEAN_BUOYS WHERE TD_TIMECODE BETWEEN TIMESTAMP '2014-01-06 08:00:00' AND TIMESTAMP '2014-01-06 10:30:00' GROUP BY TIME (MINUTES(10) AND BUOYID) ORDER BY 2,3,4; /*Non-PTI Table*/ SELECT $TD_TIMECODE_RANGE, $TD_GROUP_BY_TIME, BUOYID, LAST(TEMPERATURE) FROM OCEAN_BUOYS_NONPTI WHERE TIMECODE BETWEEN TIMESTAMP '2014-01-06 08:00:00' AND TIMESTAMP '2014-01-06 10:30:00' GROUP BY TIME (MINUTES(10) AND BUOYID) USING TIMECODE(TIMECODE) ORDER BY 2,3,4;
The ties are returned in Rows 5-7, below.
TIMECODE_ RANGE | GROUP BY TIME (MINUTES(10)) | BUOYID | Last (TEMPERATURE) |
---|---|---|---|
('2014-01-06 08:00:00.000000+00:00', '2014-01-06 08:10:00.000000+00:00') | 1 | 0 | 99 |
('2014-01-06 08:10:00.000000+00:00', '2014-01-06 08:20:00.000000+00:00') | 2 | 0 | 10 |
('2014-01-06 08:10:00.000000+00:00', '2014-01-06 08:20:00.000000+00:00') | 2 | 0 | 100 |
('2014-01-06 09:00:00.000000+00:00', '2014-01-06 09:10:00.000000+00:00') | 7 | 1 | 72 |
('2014-01-06 09:00:00.000000+00:00', '2014-01-06 09:10:00.000000+00:00') | 7 | 1 | 79 |
('2014-01-06 10:00:00.000000+00:00', '2014-01-06 10:10:00.000000+00:00') | 13 | 44 | 53 |
('2014-01-06 10:00:00.000000+00:00', '2014-01-06 10:10:00.000000+00:00') | 13 | 44 | 56 |
('2014-01-06 10:10:00.000000+00:00', '2014-01-06 10:20:00.000000+00:00') | 14 | 44 | 43 |