用于获取具有条件的最小日期的查询

vktxenjb  于 2021-06-26  发布在  Impala
关注(0)|答案(1)|浏览(301)
create table t(dt1 date,dt2 date,dt3 date,dt4 date)

    insert into t values('1970-01-01','2008-10-10',NULL,NULL),
(NULL,'2008-10-10','2017-10-12',NULL),('1970-01-01','2008-10-10',NULL,'2018-10-09')

我有这个查询的代码

select *, (select min(dates) 
           from (values (dt1), (dt2), (dt3), (dt4))a(dates)
           where a.dates > '1970-01-01') as DDt
from t;

但它对 Impala 不起作用 ^ encountered Exception syntax error

xfb7svmp

xfb7svmp1#

尝试以下语法:

select *, (select min(dt1) 
           from (select dt1 from t union select dt2 from t union select dt3 from t union select dt4 from t)a
           where a.dt1 > '1970-01-01') as DDt
from t

相关问题