如何将“%y%m%d%h%i%s”列拆分为两列:一列包含%y%m%d%,另一列包含配置单元中的h%i%s?

aydmsdu9  于 2021-06-26  发布在  Hive
关注(0)|答案(2)|浏览(352)

我有一列显示“%y%m%d%h%i%s”(例如20150125145900)如何将其转换为两列,一列是“ymd”,另一列是“his”(例如2015/01/25和14:59:00)?

js81xvg6

js81xvg61#

select datetime[0] as,datetime[1] as 小时 from (select split(from_unixtime(unix_timestamp('20150125145900','yyyyMMddhhmmss'),'yyyy-MM-dd HH:mm:ss'),' ') as datetime)e ```
year hour
2015-01-25 02:59:00

zyfwsgd6

zyfwsgd62#

Hive

select  ts[0] as year
       ,ts[1] as hour

from   (select  split(from_unixtime(unix_timestamp('20150125145900','yyyyMMddHHmmss')
                    ,'yyyy-MM-dd HH:mm:ss'),' ') as ts
        ) t
+------------+----------+
|    year    |   hour   |
+------------+----------+
| 2015-01-25 | 14:59:00 |
+------------+----------+

Impala

select  split_part(ts,' ',1) as year
       ,split_part(ts,' ',2) as hour

from   (select  from_unixtime(unix_timestamp('20150125145900','yyyyMMddHHmmss')
                    ,'yyyy-MM-dd HH:mm:ss') as ts
        ) t
;
+------------+----------+
| year       | hour     |
+------------+----------+
| 2015-01-25 | 14:59:00 |
+------------+----------+

相关问题