16.20 - 例 - Teradata Vantage NewSQL Engine

Teradata Vantage™ 時系列テーブルおよび操作

prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
プログラミング リファレンス
featnum
B035-1208-162K-JPN

例: MEDIAN関数の使用

/*PTI Table*/
SELECT $TD_TIMECODE_RANGE, $TD_GROUP_BY_TIME, BUOYID, MEDIAN(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(30) AND BUOYID)
ORDER BY 3,2,1;

/*Non-PTI Table*/
SELECT $TD_TIMECODE_RANGE, $TD_GROUP_BY_TIME, BUOYID, MEDIAN(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(30) AND BUOYID)
USING TIMECODE(TIMECODE)

結果は、両方のテーブルで同じです。

TIMECODE_RANGE GROUP BY TIME (MINUTES(10)) BUOYID Median (TEMPERATURE) Count(*)
('2014-01-06 08:00:00.000000+00:00', '2014-01-06 08:30:00.000000+00:00') 1 0 5.45000000000000E 001 5
('2014-01-06 09:00:00.000000+00:00', '2014-01-06 09:30:00.000000+00:00') 3 1 7.45000000000000E 001 6
('2014-01-06 10:00:00.000000+00:00', '2014-01-06 10:30:00.000000+00:00') 5 44 5.30000000000000E 001 11

例: HAVING句を使用した奇数の値を持つグループの報告

/*PTI Table*/
SELECT $TD_TIMECODE_RANGE, $TD_GROUP_BY_TIME, BUOYID, MEDIAN(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(30) AND BUOYID)
HAVING COUNT(*) MOD 2 = 1 AND COUNT(*) > 2
ORDER BY 3,2,1;

/*Non-PTI Table*/
SELECT $TD_TIMECODE_RANGE, $TD_GROUP_BY_TIME, BUOYID, MEDIAN(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(30) AND BUOYID)
USING TIMECODE(TIMECODE)
HAVING COUNT(*) MOD 2 = 1 AND COUNT(*) > 2
ORDER BY 3,2,1;

結果は、両方のテーブルで同じです。

TIMECODE_RANGE GROUP BY TIME (MINUTES(10)) BUOYID Median (TEMPERATURE) Count(*)
('2014-01-06 08:00:00.000000+00:00', '2014-01-06 08:30:00.000000+00:00') 1 0 5.45000000000000E 001 5
('2014-01-06 10:00:00.000000+00:00', '2014-01-06 10:30:00.000000+00:00') 5 44 5.30000000000000E 001 11