例如:
结果集A等于 select id from X;
结果集B等于 select id from Y;
sql语句如下:
select * from Z where z.id in(这里如果A不为空就是 select id from X;如果A为空就是select id from Y)其中结果集A和B都有可能是多个值。目的就是实现当结果集A一条数据都没有的时候,就选择结果集B。请教这样的情况该如何写SQL语句能实现。
最好是Oracle标准下的。
谢谢

解决方案 »

  1.   

    select * from Z where z.id in(nvl(A,B)) ???
      

  2.   


     select * from test3 where id in (select id from test1 union select id from
    test2,(select count(1) count from test1) where count=0);
      

  3.   


    select * from Z where z.id in (select id from X)
    UNION
    select * from Z where z.id in (select id from Y WHERE 0 = (SELECT COUNT(ID) FROM X))