请大家看下面的程序:
create table #temp1
(
seq_no int identity(1,1),
amount numeric(18,2)
);create table #temp2
(
seq_no int ,
amount numeric(18,2)
);insert into #temp1
values(10000);insert into #temp2 values(1,1000);
insert into #temp2 values(1,1000);
insert into #temp2 values(1,1000);
insert into #temp2 values(1,1000);
insert into #temp2 values(1,1000);
update a
set a.amount = a.amount + b.amount
from #temp1 a inner join #temp2 b
on a.seq_no = b.seq_no;select * from #temp1;
select * from #temp2;drop table #temp1;
drop table #temp2;我的想法是取出来的#temp1是15000,但是事与愿违,想请教一下大家会如何做,不要用游标的
create table #temp1
(
seq_no int identity(1,1),
amount numeric(18,2)
);create table #temp2
(
seq_no int ,
amount numeric(18,2)
);insert into #temp1
values(10000);insert into #temp2 values(1,1000);
insert into #temp2 values(1,1000);
insert into #temp2 values(1,1000);
insert into #temp2 values(1,1000);
insert into #temp2 values(1,1000);
update a
set a.amount = a.amount + b.amount
from #temp1 a inner join #temp2 b
on a.seq_no = b.seq_no;select * from #temp1;
select * from #temp2;drop table #temp1;
drop table #temp2;我的想法是取出来的#temp1是15000,但是事与愿违,想请教一下大家会如何做,不要用游标的
set a.amount =
a.amount + (SELECT SUM(b.amount ) FROM #TEMP2 WHERE a.seq_no = seq_no)
from #temp1 a inner join #temp2 b
on a.seq_no = b.seq_no; ?
不懂
set a.amount = (SELECT SUM(b.amount ) FROM #TEMP2 WHERE a.seq_no = seq_no)
from #temp1 a
set a.amount =
a.amount + (SELECT SUM(b.amount ) FROM #TEMP2 B WHERE a.seq_no =B.seq_no)
from #temp1 a