SQL Hive - 将 Int 转换为 varchar 并连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27252399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 03:01:12  来源:igfitidea点击:

Hive - convert Int to varchar and concatenate

sqlhivehql

提问by Doc Holiday

I have 2 columns I want to convert to varchars and concatenate to place them in one column:

我有 2 列我想转换为 varchars 并连接以将它们放在一列中:

How would I do this in Hive? I keep getting issues when I try the normal way in sql...

我将如何在 Hive 中做到这一点?当我在 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
select ('$' || round(min(temp) over (partition by temp2, temp3) || '-' ||
        '$' || round(max(temp)) over (partition by temp2, temp3)
       ) as minmax
-0

Answer:

回答:

This worked for me.....

这对我有用......

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

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

回答by Gordon Linoff

Try this:

尝试这个:

##代码##