如何从 HIVE 中一行的不同列中获取最大值?
例如
Row# ID# Col1 Col2 Col3
1 1234 54 67 86
2 5678 89 92 86
...
...
寻找表单的输出:
1234 86
5678 92
谢谢!
最佳答案
从 1.1 开始,Hive 具有最大的 () 函数;
select ID, greatest(col1, col2, col3) as greatest_value from table;
或者,如果您的版本没有 best(),您可以使用 case when 语句:
select ID
, case
when col1 > col2 and col1 > col3 then col1
when col2 > col3 then col2
else col3
end as greatest_value
from table
;
Case when 语句按从上到下的顺序进行评估,直到找到 true 值,因此无需在每个 when 子句中评估两个不等式。
关于hive - Hive 中的列(单行)的最大值(值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31395324/