表A(ID,COUNT)   ID为主键
 如 ID  CUNT
   1   
   2
   3
   4
   5
  表B(ID P)
如  ID   P
    1   A
    1      B
    2   C
    2   T
    2   Y
    3   N
    4   L
    5   P
统计B表中ID出现的次数  插到A表的COUNT 字段中
  如上  插入后  A表如下
ID  CUNT
 1   2
 2   3
 3   1
 4   1
 5   1

解决方案 »

  1.   

    create table t1 (cid varchar2(100),cCount int);
    insert into t1 values('1',0);
    insert into t1 values('2',0);
    insert into t1 values('3',0);create table t2 (cparid varchar2(100),aa varchar2(100));
    insert into t2 values('1','1')
    insert into t2 values('1','2')insert into t2 values('2','1')
    insert into t2 values('3','1')
    update t1 set cCount=(select count(*) from t2 where t2.cparid=t1.cid)select * from t1;1 2
    2 1
    3 1
      

  2.   

    update t1 set cCount=(select count(*) from t2 where t2.cparid=t1.cid)
      

  3.   

    update A set A.cunt = (select NVL(count(*),0) from B where A.ID = B.ID)