我正在尝试创建一个涉及计算时差的新表。表代码有效,但时差是作为字符串存储在新表中,我需要将其存储为时间数据类型。我尝试使用强制转换功能但仍然收到错误。以下是我的代码:
CREATE TABLE DREW_HEAT_HEAT_SAMPLE_2 AS(
SELECT HEAT_ID,
(max(case when SAMPLE_COUNTER = 1 then sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 2 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 3 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 4 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 5 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 6 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 7 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 8 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 9 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 10 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 11 then '_' || sample_type else '' end)
) as concat_code,
(max(TIME_TABLE_ENTRY)-min(TIME_TABLE_ENTRY)) as TIME_DIFFERENCE
FROM JHINES.ORG_HEAT_HEAT_SAMPLE
GROUP BY HEAT_ID
)
我需要以某种方式将TIME_DIFFERENCE字段转换为TIME数据类型。我很感激帮助!
答案 0 :(得分:0)
要转换为间隔,您必须首先确保减去时间戳。在不时地施放时要小心。您将在24小时内丢失任何值。
CREATE TABLE DREW_HEAT_HEAT_SAMPLE_2 AS(
SELECT HEAT_ID,
(max(case when SAMPLE_COUNTER = 1 then sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 2 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 3 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 4 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 5 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 6 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 7 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 8 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 9 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 10 then '_' || sample_type else '' end) ||
max(case when SAMPLE_COUNTER = 11 then '_' || sample_type else '' end)
) as concat_code,
(cast(max(TIME_TABLE_ENTRY) as timestamp) -cast(min(TIME_TABLE_ENTRY) as timestamp)) as TIME_DIFFERENCE
FROM JHINES.ORG_HEAT_HEAT_SAMPLE
GROUP BY HEAT_ID
)