34,576
社区成员
发帖
与我相关
我的任务
分享
declare @t1 table(A1 varchar(4),
A2 varchar(4),
A3 varchar(4)
)
insert into @t1
select '1', '2','3'
union select '1', '4','8'
union select '2', '5','3'
union select '2', '6','8'
--select * from @t1
/*A1 相同,取最小的A2 的值*/
--update b set b.a2 =(select min(a2) from @t1 where b.a1 = a1 ) from @t1 b
--select * from @t1
/*A 表中A1字段相等两条记录 把A3等于8的那一条的A2改为A3 等于3的A2 值 */
update b set b.a2=(select a2 from @t1 where b.a1 = a1 and A3 ='3' ) from @t1 b where b.a3 = '8'
select * from @t1
--Result--
A1 A2 A3
---- ---- ----
1 2 3
1 2 8
2 5 3
2 5 8
declare @t1 table(A1 varchar(4),
A2 varchar(4),
A3 varchar(4)
)
insert into @t1
select '1', '2','3'
union select '1', '4','8'
union select '2', '5','3'
union select '2', '6','8'
--select * from @t1
update b set b.a2 =(select min(a2) from @t1 where b.a1 = a1 ) from @t1 b
select * from @t1
---Result--
A1 A2 A3
---- ---- ----
1 2 3
1 2 8
2 5 3
2 5 8
update a set a2=(select A2 from a where A1=dbo.a.A1 and A3=3) from dbo.a where A3=8
update [Table] set A2=(select A2 from [Table] where A1=a.A1 where A3=3) from [Table] a where A3=8