create table tj(id varchar(22),num int)
create table qj(id varchar(22),num int)
insert into tj values ('tom',0)
insert into tj values ('mike',0)
insert into tj values ('jason',0)
insert into qj values ('tom',10)
insert into qj values ('mike',20)
update tj set num= b.su from tj,(select id,sum(num) su from qj group by id) as b where tj.id=b.id
select * from tj
tom 10
mike 20
jason 0
update tj
set dy= (select sum(qj.qjxs)
from k06qjdj qj left join k0609tj tj
on qj.id=tj.id
)
from k06qjdj qj left join k0609tj tj
on qj.id=tj.id
SELECT QJ.ID,SUM(QJ.QJXS)HJ INTO #A from k06qjdj qj left join k0609tj tj
on qj.id=tj.id
group by qj.id
UPDATE TJ SET DY=HJ FROM #A WHERE #A.ID=TJ.ID
你可以用存储过程来做,首先将你第一个查询的结果保存到一个定义的字段上,然后在第二个语句中使用这个字段如:
int @a
select @a=sum(qj.qjxs)
from k06qjdj qj left join k0609tj tj
on qj.id=tj.id
group by qj.id
update tj
set dy=@a
from k06qjdj qj left join k0609tj tj
on qj.id=tj.id
group by qj.id
看不懂。。。。