16.20 - MODE - 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

Purpose

Returns the mode of all values in each group. In the event of a tie between two or more values from value_expression, a row per result is returned. MODE is a single-threaded function.

To invoke the time series version of this function, use the GROUP BY TIME clause. For more information, see GROUP BY TIME Clause.

Syntax



Syntax Elements

value_expression
A literal or column expression for which a median is to be computed.

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.

Nulls are not included in the result computation.

Usage Notes

MODE is valid only for numeric data.

Example: Using MODE with Time Series

/*PTI Table*/
SELECT $TD_TIMECODE_RANGE, $TD_GROUP_BY_TIME, BUOYID, MODE(TEMPERATURE), COUNT(*)
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 3,2,4;

/*Non-PTI Table*/
SELECT $TD_TIMECODE_RANGE, $TD_GROUP_BY_TIME, BUOYID, MODE(TEMPERATURE), COUNT(*)
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 3,2,4;

The results are the same for both tables:

TIMECODE_RANGE GROUP BY TIME (MINUTES(10)) BUOYID Mode (TEMPERATURE) Count(*)
('2014-01-06 08:00:00.000000+00:00', '2014-01-06 08:10:00.000000+00:00') 1 0 10 3
('2014-01-06 08:00:00.000000+00:00', '2014-01-06 08:10:00.000000+00:00') 1 0 99 3
('2014-01-06 08:10:00.000000+00:00', '2014-01-06 08:20:00.000000+00:00') 2 0 10 2
('2014-01-06 08:10:00.000000+00:00', '2014-01-06 08:20:00.000000+00:00') 2 0 100 2
('2014-01-06 09:00:00.000000+00:00', '2014-01-06 09:30:00.000000+00:00') 7 1 70 6
('2014-01-06 09:00:00.000000+00:00', '2014-01-06 09:30:00.000000+00:00') 7 1 71 6
('2014-01-06 09:00:00.000000+00:00', '2014-01-06 09:30:00.000000+00:00') 7 1 72 6
('2014-01-06 09:00:00.000000+00:00', '2014-01-06 09:30:00.000000+00:00') 7 1 77 6
('2014-01-06 09:00:00.000000+00:00', '2014-01-06 09:30:00.000000+00:00') 7 1 78 6
('2014-01-06 09:00:00.000000+00:00', '2014-01-06 09:30:00.000000+00:00') 7 1 79 6
('2014-01-06 10:00:00.000000+00:00', '2014-01-06 10:10:00.000000+00:00') 13 44 43 10
('2014-01-06 10:10:00.000000+00:00', '2014-01-06 10:20:00.000000+00:00') 14 44 43 1