select * from c where c.col in (select decode(c2,c1,'1',c3,'3','2') from 
(select count(*) c1 from b) a,
(select count(*) c2 from b where col is not null) b,
(select count(*) c3 from b where col is null) c )
//b为a查出来的结果集
such as select * from a where sex='M'

解决方案 »

  1.   

    楼上兄弟,可能我表述有点错误,应该是:
    先从表A查找出结果集B,再根据结果集B的情况,比如说字段a全部都有值则得出1,部分有值则得出2,一个值都没则得出3,将值付给变量y,再根据y到另一表C中查找数据,请问这样能在一个SQL语句里面完成吗?如何写?关键是这个变量如何写进去
      

  2.   

    那样一句就不成了阿
    我上边的加个注释你就明白了
    select * from c where c.col in ( 
       //下面的只得到一个值,它作为查询c的条件
    select decode(c2,c1,'1',c3,'3','2') from   //如果不空的=总数得1 全空的 3 部分 2
    (select count(*) c1 from b) a, //共有多少条
    (select count(*) c2 from b where col is not null) b, //不空的多少条
    (select count(*) c3 from b where col is null) c //孔的多少条
     )
    //b为a查出来的结果集
    such as select * from a where sex='M'
    注:对结果集可以相对表一样查询的
    所以先从表A查找出结果集B,再根据结果集B的情况就没用了
    你可以把具体的表名列名给我,我给你写出来
    肯定对的