update 表A
set Count=(select count(PID) from 表B where pid=a.id)
from 表A a

解决方案 »

  1.   

    update D 
      set D.count=C.cc
     from 表A D inner join  (select cc=count(*),A.ID from 表A A inner join 表B B on A.ID=B.PID group by A.ID) C
        on C.ID=.ID
      

  2.   

    Update 表A Set 
    Count=(Select Count(表B.PID) from 表B Where 表A.ID=表B.ID  Group By 表B.ID)
    from 表B
      

  3.   

    错了,去掉一点Update 表A Set 
    Count=(Select Count(表B.PID) from 表B Where 表A.ID=表B.ID )
    from 表B
      

  4.   

    楼主,有错误提示没??提示是什么??--------------------------
    表A :ID ,Count
    表B :ID,PID
    其中ID-->PID
    如何用一个更新语句实现更新表A中的count的内容等于A.ID=B.PID中的PID的个数
    -------------------------你的表述有点问题,A的ID和B中PID对应,那怎么还要统计PID的个数??
      

  5.   

    select c, count(*) as cou into #temp from bb group by c
    update aa set b=(select cou from #temp where aa.a=#temp.c)
    這樣一定行﹗
    調試過
      

  6.   

    不知道楼主是不是这个意思。Update 表A Set Count=(Select Count(ID) from 表B Where 表B.PID=表A.ID)
      

  7.   

    declare @t table (city nvarchar(10) null,id int,c int)
    insert into @t(id,c) select 1,1 union all select 2,2 union all select 3,3declare @t2 table (id int,cid int)
    insert into @t2(id,cid) select 1,1 union all select 2,2 union all select 3,3 union all select 1,1select * from @t a
    select * from @t2 aupdate a
    set c=(select count(cid) from @t2 b where cid=a.id )
    from @t aselect * from @t a