--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')
--应该还可以这样,你试试呢: 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是笛卡尔积,有可能条数就不准确,不知道你想要的是什么效果。
--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')
--应该还可以这样,你试试呢:
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是笛卡尔积,有可能条数就不准确,不知道你想要的是什么效果。
--笛卡尔积 不准确,第一种效果是正确的,是我想要的。
我第一种是你要的结果,那么也只有先算了A表那天的数据条数再想减了。
--这样简单:
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 );
发贴时要编辑才能发代码。