求帮写一条修改SQL语句(在线等待)
UPDATE a SET Fid=b.id
FROM #ta2 a
JOIN #ta1 b ON a.Ftx=b.tx
create table #ta1(id int ,tx varchar(20))
go
insert into #ta1
select 1,'小明' union all
select 2,'小红' union all
select 3,'小李'
go
create table #ta2(id int,Ftx varchar(20),Fid int)
go
insert into #ta2
select 1,'小明',0 union all
select 2,'小明',0 union all
select 3,'小李',0 union all
select 4,'小李',0 union all
select 5,'小军',0 union all
select 6,'小军',0
update #ta2
set Fid = t1.id
from #ta2 t2
inner join #ta1 t1
on t2.Ftx = t1.tx
select *
from #ta2
/*
idFtxFid
1小明1
2小明1
3小李3
4小李3
5小军0
6小军0
*/