日期:2014-05-18 浏览次数:20749 次
create table a (id int identity,bcount int)
create table b (id int identity,aid int)
insert a select null union all select null union all select null
insert b select 2 union all select 1 union all select 1
select * from a
/*
id bcount
1 NULL
2 NULL
3 NULL
*/
select * from b
/*
id aid
1 2
2 1
3 1
*/
update a set bcount=(select count(1) from b where a.id=b.aid group by b.aid)
/*
id bcount
1 2
2 1
3 NULL
*/
drop table a
drop table b