-2
select * from table1 t1 where t1.column1 = 'someValue' and ((t1.column2 =1) OR  (sysdate < select t1.DateColumn2 + t2.DateColumn2/1440
      from
    table2 t2 where t1.column3 = t2.column3));

如果 t1.column2 =1 评估为假,我想检查另一个条件,如果时间 t1.DateColumn2 + t2.DateColumn2 是 < sysdate 。Oracle 在或条件附近抛出语法错误。不能这样直接使用sysdate吗?不知道我哪里出错了。谢谢

4

1 回答 1

0

如果我猜对了你的意图,你想要一个exists子句

select * 
  from table1 t1 
 where t1.column1 = 'someValue' 
   and (   (t1.column2 =1) 
        OR exists( select 1
                     from table2 t2
                    where t2.column3 = t1.column3
                      and sysdate < t1.DateColumn2 + t2.DateColumn2/1440 ));

或者只是连接外部查询中的两个表,假设t2t1行最多有 1 行(如果正好有 1 行,你应该做一个内连接而不是左外连接)

select t1.*
  from table1 t1
       left outer join table2 t2
         on( t1.column3 = t2.column3 )
 where t1.column2 = 1
    or sysdate < t1.DateColumn2 + t2.DateColumn2/1440;
于 2020-09-17T12:47:34.023 回答