A 表A字段   B字段1       aaa
2       bbb
3       cccc
===========================    
B 表 A字段   C字段1       jjjjj2       flala1       ajkjf3       jjjjj2       jjjjj 
===========================C 表A字段   D字段1       KKKK3       ueiaa2       KKKK1       KKKK3       KKKK2       KKKK       
===========================
D 表
A字段               E字段(在B表中满足bb.c='jjjjj'的记录数)                          F字段(在C表中满足cc.d='KKKK'的记录数)
1        select count(*) from B bb where bb.c='jjjjj' and bb.a=1;          select count(*) from C cc  where cc.d='KKKK' and cc.a=1; 
2  select count(*) from B bb where bb.c='jjjjj' and bb.a=2;          select count(*) from C cc  where cc.d='KKKK' and cc.a=2;
3  select count(*) from B bb where bb.c='jjjjj' and bb.a=3;          select count(*) from C cc  where cc.d='KKKK' and cc.a=3;===========================我想按表A,字段A分组统计出满足条件的数量,然后插入到D表,实行的结果如上面的D表,希望用一条SQL语句实行,其中C表
有百万级的数据,按字段A分了区,希望求得一条高效的语句,谢谢了!!

解决方案 »

  1.   

    ===========================
    D 表
    A字段 E字段(在B表中满足bb.c='jjjjj'的记录数)  F字段(在C表中满足cc.d='KKKK'的记录数)
    1   select count(*) from B bb where bb.c='jjjjj' and bb.a=1; select count(*) from  C  cc where c.d='KKKK'and cc.a=1; 
    2   select count(*) from B bb where bb.c='jjjjj' and bb.a=2; select count(*) from C cc  where cc.d='KKKK' and cc.a=2;
    3  select count(*) from B bb where bb.c='jjjjj' and bb.a=3;  select count(*) from C cc  where cc.d='KKKK' and cc.a=3;===========================
      

  2.   

    select A.a,t.cb,v.cc
    from 
    A,
    (select a,count(1) cb from B where B.c='jjjj' group by a) t,
    (select a,count(1) cc from C where C.d='KKKK' group by a) v,
    where A.a=t.a(+) and A.a=v.a(+)
      

  3.   

    select A.a,sum(decode(B.c,'jjjj',1,0)),sum(decode(C.d,'kkkk',1,0))
    from A,B,C
    where A.a=B.a(+)  and A.a=C.a(+)
      

  4.   

    SELECT A.A,COUNT(B.A),COUNT(C.A)
      FROM A,(SELECT A   FROM B  WHERE B.C='JJJJ') B1,
             (SELECT A   FROM C  WHERE C.D='KKKK') C1
    WHERE A.A=B1.A(+)
      AND A.A=C1.A(+)
    GROUP BY A.A;