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) 這樣一定行﹗ 調試過
不知道楼主是不是这个意思。Update 表A Set Count=(Select Count(ID) from 表B Where 表B.PID=表A.ID)
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
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
Count=(Select Count(表B.PID) from 表B Where 表A.ID=表B.ID Group By 表B.ID)
from 表B
Count=(Select Count(表B.PID) from 表B Where 表A.ID=表B.ID )
from 表B
表A :ID ,Count
表B :ID,PID
其中ID-->PID
如何用一个更新语句实现更新表A中的count的内容等于A.ID=B.PID中的PID的个数
-------------------------你的表述有点问题,A的ID和B中PID对应,那怎么还要统计PID的个数??
update aa set b=(select cou from #temp where aa.a=#temp.c)
這樣一定行﹗
調試過
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