標題: update問題 [打印本頁] 作者: ARISYANG 時間: 2007-02-15 10:09 標題: update問題 create table a(
a varchar(10) null,
b number(5) null
)
insert into a values ('a','1')
insert into a values ('a','2')
insert into a values ('a','3')
insert into a values ('b','4')
insert into a values ('b','5')
create table b(
a varchar(10) null,
b number(5) null
)
insert into b(a) (select distinct a from b)
現(xiàn)在b表有數(shù)據(jù)a,b
我現(xiàn)在的需求是update b set b=count(*) from
(
select a,count(b)
from a
group by a
)
where a.a=b.a
請問怎么寫SQL?作者: jasonshan 時間: 2007-02-16 10:24
select a,count(b) as b into #tmp1 from a group by a
update b set b.b=#tmp1.b from #tmp1 where b.a=#tmp1.a作者: ARISYANG 時間: 2007-02-16 16:40
恩,就是這樣做的,不能用子查詢