Skip to content
Advertisement

“Hive” max column value from multiple columns

Hi: I have a situation where I need to find the max value on 3 calculated fields and store it in another field, is it possible to do it in one SQL query? Below is the example

One way I tried is to calculate Personal_Income, Share_Income, Job_Income in the first pass and in the second pass I used

but this require me to do 2 scans on a billion rows table, How can I avoid this and do it in a single pass? Any help much appreciated.

Advertisement

Answer

As of Hive 1.1.0 you can use greatest() function. This query will do in a single table scan:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement