本帖最后由 fzlme5 于 2011-02-14 21:16:20 编辑

解决方案 »

  1.   


    --1、求A表时间是2011-02-14这天总的数据条数:
    select count(*) a_cnt from A where to_char(e,'yyyy-MM-dd')='2011-02-14' ;
    --2、再求出A、B在2011-02-14这天相关联的数据条数:
    select count(*) a_b_cnt from a s0,b s1 where s0.c=s1.c and s0.d=s1.d and to_char(s0.e,'yyyy-MM-dd')='2011-02-14'; 
    --3、A、B在2011-02-14这天不相关联的数据条数:
    a_cnt-a_b_cnt--因此:
    select a_cnt-a_b_cnt from
    (select count(*) a_cnt from A s0 where to_char(s0.e,'yyyy-MM-dd')='2011-02-14'),
    (select count(*) a_b_cnt from a s0,b s1 where s0.c=s1.c and s0.d=s1.d and to_char(s0.e,'yyyy-MM-dd')='2011-02-14')
      

  2.   


    --应该还可以这样,你试试呢:
    select count(*) from a s0,b s1 where (s0.c!=s1.c or s0.d!=s1.d) and to_char(s0.e,'yyyy-MM-dd')='2011-02-14'; --这样A、B是笛卡尔积,有可能条数就不准确,不知道你想要的是什么效果。
      

  3.   

    TO:gelyon
    --笛卡尔积 不准确,第一种效果是正确的,是我想要的。
      

  4.   

    记忆中Oracle有个函数是求减的。久了没用忘的差不多了!
      

  5.   

    由于你e只有A表中有,笛卡尔积肯定会数据不准确。
    我第一种是你要的结果,那么也只有先算了A表那天的数据条数再想减了。
      

  6.   


    --这样简单:
    select count(*) from a s0 where to_char(s0.e,'yyyy-MM-dd')='2011-02-14'
    and not exists(select 1 from b s1 where s0.c=s1.c and s0.d=s1.d ); 
      

  7.   

    怎么我的CSDN发贴和回帖都不能贴代码?都提示XML解析错误,1行,1列。
    发贴时要编辑才能发代码。