2017-04-06 34 views
0

我已經在hadoop上安裝了hive 2.1.1,其中我使用列(dis string,dt timestamp)創建了名稱數據表。我想將日期和時間存儲在單獨的列中,因此我創建了名稱爲data1和列(dis string,dat date,time string)的另一個表。我怎樣才能從表格數據複製數據到data1。 我曾試圖通過做「插入到表data1選擇dis,轉換(日期,dt),轉換(時間,dt)從數據;」。如何從時間戳中分離日期和時間,並將其存儲在配置單元中的另一個表中

回答

0

下面查詢使用

insert into table data1 select dis,TO_DATE(dt),concat(HOUR(DT),':',MINUTE(dt)) from data; 
+0

(1)什麼用秒? (2)爲什麼使用'concat'而不是'concat_ws'? –

+0

我剛剛提供樣品以包括時間,我們可以根據我們的要求使用。是的,我們也可以使用concat_ws ..謝謝 –

0
select dis,to_date(dt),split(dt,' ')[1] 

select dis,to_date(dt),substr(dt,12,8) 

演示

with t as (select timestamp '2017-04-06 04:20:33' as dt) 
select to_date(dt),split(dt,' ')[1] from t; 
OK 
_c0 _c1 
2017-04-06 04:20:33 

with t as (select timestamp '2017-04-06 04:20:33' as dt) 
select to_date(dt),substr(dt,12,8) from t; 
OK 
_c0 _c1 
2017-04-06 04:20:33 
相關問題