gpt4 book ai didi

hadoop - Hive 查询以从字符串中分别提取日期和小时

转载 作者:可可西里 更新时间:2023-11-01 14:45:16 24 4
gpt4 key购买 nike

我需要从配置单元的字符串列中提取日期和小时。

表格: enter image description here

select TO_DATE(from_unixtime(UNIX_TIMESTAMP(dates,'dd/MM/yyyy'))) from dates;

output:

0016-01-01
0016-01-01

select TO_DATE(from_unixtime(UNIX_TIMESTAMP(dates,'hh'))) from dates;

output:

1970-01-01
1970-01-01

请告知如何从表格列中分别取日期和小时。

最佳答案

我已将数据样本更改为更合理的内容

with dates as (select explode(array('1/11/16 3:29','12/7/16 17:19')) as dates)

select from_unixtime(unix_timestamp(dates,'dd/MM/yy HH:mm'),'yyyy-MM-dd') as the_date
,from_unixtime(unix_timestamp(dates,'dd/MM/yy HH:mm'),'H') as H
,from_unixtime(unix_timestamp(dates,'dd/MM/yy HH:mm'),'HH') as HH

from dates

+------------+----+----+
| the_date | h | hh |
+------------+----+----+
| 2016-11-01 | 3 | 03 |
| 2016-07-12 | 17 | 17 |
+------------+----+----+

关于hadoop - Hive 查询以从字符串中分别提取日期和小时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43576355/

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