Presto 中的每行最小值
Min per row in Presto
我有一个 table,在 PrestoDB 中有 4 个 timestamp tz
类型的列 - 没有 NULL 值 - 我无法获得每行的最小值。这似乎违反直觉,因为:
SELECT
(SELECT MIN(Col) FROM (VALUES (1), (2), (3), (4)) AS X(Col)) AS TheMin
FROM mytable
^ 使用伪整数将为所有行 return 1
然而在我的 table:
SELECT
(SELECT MIN(Col) FROM (VALUES (_col2), (_col3), (_col4), (_col5)) AS X(Col)) AS TheMin
FROM mytable
returns Presto query has failed. type cannot be null
当列中的数据类型都是 timestamp tz
并且有零个 NULL 值时,这怎么可能?
使用 VALUES
列查找每行的最小时间戳的解决方法是什么?
只需使用LEAST()
:
SELECT LEAST(_col2, _col3, _col4), _col5) as TheMin
FROM mytable
我有一个 table,在 PrestoDB 中有 4 个 timestamp tz
类型的列 - 没有 NULL 值 - 我无法获得每行的最小值。这似乎违反直觉,因为:
SELECT
(SELECT MIN(Col) FROM (VALUES (1), (2), (3), (4)) AS X(Col)) AS TheMin
FROM mytable
^ 使用伪整数将为所有行 return 1
然而在我的 table:
SELECT
(SELECT MIN(Col) FROM (VALUES (_col2), (_col3), (_col4), (_col5)) AS X(Col)) AS TheMin
FROM mytable
returns Presto query has failed. type cannot be null
当列中的数据类型都是 timestamp tz
并且有零个 NULL 值时,这怎么可能?
使用 VALUES
列查找每行的最小时间戳的解决方法是什么?
只需使用LEAST()
:
SELECT LEAST(_col2, _col3, _col4), _col5) as TheMin
FROM mytable