我需要施加持续时间,以秒为单位,十进制(18,0)到小时,分钟和秒。
e.g.:
8192 Seconds => 2:16:32 (Hours:Minutes:Seconds)
我发现(here)我可以这样做,如果秒是一个文字字符串,就像这样:
SELECT CAST(INTERVAL '8192' SECOND AS INTERVAL HOUR TO SECOND)
但是当我尝试时:
SELECT Event_Id
, CAST(INTERVAL Duration SECOND AS INTERVAL HOUR TO SECOND)
FROM EVENT_TABLE
WHERE <some conditions>
Event_Id和Duration都在表EVENT_TABLE
中声明为十进制(18,0)
Teradata抱怨道:
[错误3707] 语法错误,预期类似于'INTERVAL'关键字和整数8之间的字符串或Unicode字符文字
这里使用的正确语法或方法是什么?
解决方案:基于BellevueBob的帖子
SELECT Event_Id
, CAST(
Duration SECOND * INTERVAL '0000:01' MINUTE TO SECOND /* 1 */
AS INTERVAL HOUR TO SECOND /* 2 */
)
FROM EVENT_TABLE
WHERE <some conditions>
说明:
答案 0 :(得分:3)
从您找到的相同解决方案中,试试这个:
select CAST(duration * INTERVAL '0000:01' MINUTE TO SECOND
AS INTERVAL HOUR TO SECOND)
from (
select cast(8192 as decimal(18,0)) as duration
) x