fid,fName,fdbID 1 A 1 2 B 1 1 A 2 ------------------------------------------------- 就是把 fdbID=2 的记录和fDbID=1 的记录做比较 如果fName相同 把fid 修改成 (fdbID=1)的fid 请问怎么写?
------解决方案-------------------- update a set fid = (select min(fid) from a where fName = t.fName) from a t
------解决方案--------------------
SQL code
create table a(fid int,fName varchar(10),fdbID int)
insert into a values( 1 ,'A', 1)
insert into a values( 2 ,'B', 1)
insert into a values( 9 ,'A', 2)
go
update a set fid = (select min(fid) from a where fName = t.fName) from a t
select * From a
drop table a
/*
fid fName fdbID
----------- ---------- -----------
1 A 1
2 B 1
1 A 2
(所影响的行数为 3 行)
*/
------解决方案--------------------
SQL code
update t2
set fid=t1.fid
from a as t1 inner join a as t2 on t1.fname=t2.fname
where t1.fdbID=1 and t2.fdbID=2
------解决方案--------------------
------解决方案-------------------- vfp9.0: sele * from a where fDbID=1 into table my1 sele * from a where fDbID=2 into table my2 update my2 set my2.fid =my1.fid from my1 where my2.fName=my1.fName sele * from my2 union sele * from my1 into table result
------解决方案--------------------