2014-12-02 22 views
3

我有2列我要轉換爲VARCHAR處理並串連將它們放置在一列:蜂巢 - 轉換詮釋爲varchar和串聯

我將如何做到這一點的蜂巢?我不斷收到的問題時,我嘗試在SQL正常的方式...

round(min(temp) over (partition by temp2, temp3) min, 
round(max(temp)) over (partition by temp2, temp3) max 

*original columns* 
min max 
0 100 

============================ =========

*new column* 
min-max 
$0-$100 

答:

這個工作對我.....

concat('$',cast(round(min(temp)) as string), ' - $', cast(round(max(temp)) as string)) over (partition by temp2, temp3) newColumn

+1

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-TypeConversionFunctions – Tomalak 2014-12-02 15:19:39

+0

thanxx用於鏈路...... – 2014-12-02 15:56:56

回答

0

試試這個:

select ('$' || round(min(temp) over (partition by temp2, temp3) || '-' || 
     '$' || round(max(temp)) over (partition by temp2, temp3) 
     ) as minmax 
+0

感謝名單....上述我的聯繫以下找到了concat和cast功能。這是我用過的,它的工作原理:'concat('$',cast(round(min(temp))as string,' - $',cast(round(max(temp))as string))over由temp2,temp3)newColumn' – 2014-12-02 15:56:40

+1

這也應該工作,但'concat()'應該自動將數據類型轉換爲字符串。 – 2014-12-02 17:10:07

+0

在HIVE中,concat()不會轉換爲字符串,而是會給出錯誤。 – 2017-07-20 19:17:25