Seems like you would want the results as:
7
3

Here is one way to get the maximum value for a collection of columns with a 
case statement.
(this not done in Hive but hive case statements should work same way)

## data in table xyz

select * from xyz ;
c1 | c2 | c3
----+----+----
  2 |  1 |  3
  3 |  2 |  1
  1 |  2 |  3
(3 rows)

## Use case statements
select
   case when (c1 > c2) and (c1 > c3 )      then  c1
        when (c2 > c1) and (c2 > c3 )      then  c2
        else c3
   end  max_col
   from xyz
;

## results

max_col
---------
       3
       3
       3
(3 rows)



From: Sachin Sudarshana [mailto:[email protected]]
Sent: Friday, March 01, 2013 11:47 AM
To: [email protected]
Subject: Finding maximum across a row

Hi,

Is there any function/method to find the maximum across a row in hive?

Suppose i have a table like this:

ColA   ColB   ColC
2          5          7
3          2          1

I want the function to return

7
1


Its urgently required. Any help would be greatly appreciated!



--
Thanks and Regards,
                Sachin Sudarshana

Reply via email to