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;
但它没有处理黑斑羚并且在下面给出错误 -
^ encountered Exception syntax error
答案 0 :(得分:1)
试试这个语法:
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