sql update 子查询修改

2025-03-24 08:02:01
推荐回答(4个)
回答(1):

我试过update t A set r2=(select r2 from t B where B.r2=A.r2) where r2=3 这样说有语法错误..

这句话是错的

应该是这样:
update t set r2=(select r2 from t B,T A where B.r2=A.r2)
where r2=3
但是我不明白你的意思B.r2=A.r2??什么意思??

你HI我把

回答(2):

update t A set r2=(select TOP 1 r2 from t B where B.r2=A.r2) where r2=3

回答(3):

update t set r2 = (select distinct r2 from t where r2 <> 3) where r2 = 3

回答(4):

不用别名,用户表明.字段名,试试