Max (in value) of columns (in a single row) in Hive -
how max value different columns row in hive?
for instance
row# id# col1 col2 col3 1 1234 54 67 86 2 5678 89 92 86 ... ...
looking output of form:
1234 86 5678 92
thanks!
hive has greatest() function of 1.1;
select id, greatest(col1, col2, col3) greatest_value table;
or can use case when statement if version doesn't have greatest():
select id , case when col1 > col2 , col1 > col3 col1 when col2 > col3 col2 else col3 end greatest_value table ;
case when statements evaluated in order top bottom until value of true found, no need evaluate 2 inequalities in each when clause.
Comments
Post a Comment