gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:14:30 26 4
gpt4 key购买 nike

我有 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

最佳答案

尝试这个:

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

关于sql - Hive - 将 Int 转换为 varchar 并连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27252399/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com