'How to find the min of multiple values in HIVE?
Hive has min(col) to find the minimum value of a column. But how about finding the minimum of multiple values (NOT one column), for example
select min(2,1,3,4);
returns
FAILED: UDFArgumentTypeException Exactly one argument is expected
Any tips?
Solution 1:[1]
Found the solution!
Instead of min(col)
, we should use least(a, b, c, d)
Solution 2:[2]
Instead of using MIN, use LEAST method to find the minimum values form given values/columns^^rows.
select least(2,1,3,4);
Solution 3:[3]
Use below to find the minimum value from multiple columns.
It will produce minimum value from each row.
select least(col1,col2) as least_value from table_name;
It will produce minimum value from all rows.
select min(least(col1,col2)) as least_value from table_name;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kaushik Nayak |
Solution 2 | |
Solution 3 | surendra g |