Skip to content
Advertisement

How to get min and max from 7 columns in Hive Hue excluding zeros

I have a table which has 9 columns. Below is the structure of it

Raw Table Structure

I need the min and max of these columns for a row excluding zeros. Below is the required table structure

Output Required

If you see the columns min and max, min is minimum of 7 cols (col1 to col7) in a particular row excluding zero and max is the maximum of the 7 cols (col1 to col7) for that row.

Please help me to accomplish this in hive (hue).

Advertisement

Answer

You can use least and greatest to get the min and max, and use when to remove 0.

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