select * from    user t
where 
    t.userId = 1
and     t.age > (select b.age from b b where b.id = #id#)
如果红色语句查询是  null  最下面的条件就不需要  了  怎么写 

解决方案 »

  1.   


    select * from    user t
    where 
        t.userId = 1
    and     t.age > case when (select b.age from b b where b.id = #id#) is null then 0
    else
    (select b.age from b b where b.id = #id#)
    end
      

  2.   

    select * from    user t
    where 
        t.userId = 1
    and 
    ( t.age > (select b.age from b b where b.id = #id#)  or
      0=(select nvl(max(b.age),0) from b where b.id = #id#))
      

  3.   

    SELECT *
      FROM USER t, (SELECT b.age FROM b b WHERE b.id = #id#) d
     WHERE t.userId = 1
       AND t.age > nvl(d.age, t.age - 1)
      

  4.   

    如果B 表查出来的是托条数据:
    SELECT *
      FROM USER t, (SELECT max(b.age) age FROM b b WHERE b.id = #id#) d
     WHERE t.userId = 1
       AND t.age > nvl(d.age, t.age - 1)