Hive - 将Int转换为varchar并连接

时间:2014-12-02 14:59:29

标签: sql hive hql

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

我如何在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
$0-$100

答案:

这对我有用.....

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

1 个答案:

答案 0 :(得分:2)

试试这个:

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