gpt4 book ai didi

sql - Teradata 连接多个字符串列格式作为时间戳

转载 作者:搜寻专家 更新时间:2023-10-30 23:36:05 26 4
gpt4 key购买 nike

我对 Teradata 还是很陌生,所以请原谅,但我有两列,一列是日期,一列是 4 位 varchar 作为时间(24 小时)

下面是我用来连接字段以使其可读的内容,但我想让结果作为有效的时间戳出现,以便我可以执行计算。

cast(SCHEDULE_DATE as date format 'yyyy-mm-dd') || ' ' || substr(START_TIME,0,3) || ':' || substr(START_TIME,2,2)

这是我从上述查询中获得的结果示例。2017-01-25 13:30

当我像这样运行查询时

cast(cast(SCHEDULE_DATE as date format 'yyyy-mm-dd') || ' ' || substr(START_TIME,0,3) || ':' || substr(START_TIME,2,2) as Timestamp ) as TESTVALUE

我得到无效的时间戳

最佳答案

select  '2017-02-15'    as schedule_date
,'2233' as start_time
,to_timestamp (schedule_date || start_time,'yyyy-mm-ddhh24mi') as ts
;

+---------------+------------+----------------------------+
| schedule_date | start_time | ts |
+---------------+------------+----------------------------+
| 2017-02-15 | 2233 | 2017-02-15 22:33:00.000000 |
+---------------+------------+----------------------------+

附言
substr 参数错误。
Teradata 使用 1 作为起点。


select  '1234'                  as start_time
,substr(start_time,0,3) as original_1
,substr(start_time,2,2) as original_2
,substr(start_time,1,2) as correct_1
,substr(start_time,3,2) as correct_2
;

+------------+------------+------------+-----------+-----------+
| start_time | original_1 | original_2 | correct_1 | correct_2 |
+------------+------------+------------+-----------+-----------+
| 1234 | 12 | 23 | 12 | 34 |
+------------+------------+------------+-----------+-----------+

关于sql - Teradata 连接多个字符串列格式作为时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42259209/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com