Hive中列(单行)的最大值(以值计) [英] Max (in value) of columns (in a single row) in Hive
本文介绍了Hive中列(单行)的最大值(以值计)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如
<$ p
如何从HIVE中的某一行的不同列中获取最大值? $ p> 行#编号#Col1 Col2 Col3
1 1234 54 67 86
2 5678 89 92 86
...
...
寻找表格的输出:
1234 86
5678 92
谢谢!
解决方案
Hive具有1.1中最大的()函数;
从表中选择ID最大(col1,col2,col3)作为greatest_value;
或者,如果您的版本没有最大值, p>
select ID
,case
当col1> col2和col1> col3然后col1
当col2> col3然后col2
else col3
结束为最大值
从表
;
如果从上到下按顺序评估语句,直到找到真值,需要评估每个when子句中的两个不等式。
How do I get max value from different columns from a row in HIVE?
For instance
Row# ID# Col1 Col2 Col3
1 1234 54 67 86
2 5678 89 92 86
...
...
Looking for output of the form:
1234 86
5678 92
Thanks!
解决方案
Hive has the greatest() function as of 1.1;
select ID, greatest(col1, col2, col3) as greatest_value from table;
Or you can use a case when statement if your version doesn't have greatest():
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 statements are evaluated in order from top to bottom until a value of true is found, so no need to evaluate two inequalities in each when clause.
这篇关于Hive中列(单行)的最大值(以值计)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文