2

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?

Osiris
  • 1,007
  • 4
  • 17
  • 30
  • kindly refer to these links - [exact question](https://stackoverflow.com/questions/26276698/hive-finding-min-of-n-columns-in-a-row), [StackEx Discussion](https://dba.stackexchange.com/questions/21542/what-is-the-most-efficient-way-to-get-the-minimum-of-multiple-columns-on-sql-ser) – samkart May 08 '18 at 02:03

3 Answers3

5

Found the solution!

Instead of min(col), we should use least(a, b, c, d)

Kaushik Nayak
  • 30,772
  • 5
  • 32
  • 45
Osiris
  • 1,007
  • 4
  • 17
  • 30
1

Instead of using MIN, use LEAST method to find the minimum values form given values/columns^^rows.

select least(2,1,3,4);
0

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;

surendra g
  • 19
  • 2