Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hive - convert Int to varchar and concatenate

Tags:

sql

hql

hive

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

How would I do this in Hive? I keep getting issues when I try the normal way in 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

Answer:

This worked for me.....

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

like image 694
Doc Holiday Avatar asked Nov 01 '22 13:11

Doc Holiday


1 Answers

Try this:

select ('$' || round(min(temp) over (partition by temp2, temp3) || '-' ||
        '$' || round(max(temp)) over (partition by temp2, temp3)
       ) as minmax
like image 155
Gordon Linoff Avatar answered Nov 15 '22 07:11

Gordon Linoff