表A
ID  CNT   C   D
1   1   2   2
1   1   2   2
1   1   2   2
表B
ID  CNT  P   Q
1   3   6   6表B数据应当为 
ID  CNT  P   Q
1    1   2   2
由于表A重复所以导致表B成倍怎样更具表A写一个循环让表B数据正确?

解决方案 »

  1.   

    描述的是有点不清楚 你先看看这样是你要的吗?update b set cnt=cnt/(select count(*) from a where a.id=b.id),
    p=p/(select count(*) from a where a.id=b.id),
    q=q/(select count(*) from a where a.id=b.id);
    commit;
      

  2.   

    update b set (b.p,b.q)=(select a.c,a.d from a where a.id=b.id and a.cnt=b.cnt)
      

  3.   

    merge into B 
    using A
    on (A.ID = B.ID)
    when matched then
      update set b.cnt = a.cnt,b.p = a.p b.q = a.q
    when not matched then
      insert(id,cnt,p,q)
      values(a.id,a.cnt,a.p,a.q)