22,294
社区成员
发帖
与我相关
我的任务
分享
update a
set a.col=b.col
from 主表 a,从表 b
where a.id=b.id and b.[name]='张鑫'
/*
从表,名叫:张鑫
主表,名叫:商机信息表
想把从表:张鑫 内容 更新到 主表商机信息表,应该怎么写,谢谢各
*/
update 主表 set z.col=c.col2 from 主表 Z join 从表 c on Z.id=c.id
create table tb1(id int,col1 int)
insert into tb1 select 1,4 union all select 2,8 union all select 3,2
create table tb2(id int,col1 int)
insert into tb2 select 1,3 union all select 2,6 union all select 3,8
update tb2 set col1=b.col1 from tb2 a inner join tb1 b on a.id=b.id
select * from tb2
go
drop table tb1,tb2
/*
id col1
----------- -----------
1 4
2 8
3 2
*/
update a set a.名叫=b.名叫
from 商机信息表 a
join 张鑫 b on a.id=b.id