Benvorth Benvorth - 6 months ago 17
SQL Question

SAP HANA: Minimum value of several columns

I have some columns in SAP HANA Index Server:

ID | COL_1 | COL_2 | COL_3
---+-------+-------+------
1 | 5 | 3 | 2
2 | 7 | 9 | 8
3 | 5 | 4 | 6


How can I get the minium value per line?

Expected result:

ID | MIN
---+-------
1 | 2
2 | 7
3 | 4


So far I tried

SELECT ID, min(COL_1, COL_2, COL_3) FROM ...


But
min()
seems to support only two cols at a time.

Answer

Assuming none of the values are NULL, then use LEAST():

select least(col_1, col_2, col3_3)
from . . .