Create Table Active1 (Name Varchar(20), ID int IDENTITY(1,1))
Select * from Active1
NAME ID
-------------------- ----------------------
vj 102
vj 103
vj 104
vj 105
vj 106
swami 108
swami 109
需要输出
vj 106
vj 106
vj 106
vj 106
vj 106
vj 106
vj 106
vj 106
vj 106
swami 108
swami 109
(动态获取和更新值)
Update Active1 SET ID=(select MAX(ID) from Active1 where Name = (select NAME from Active1) group by name HAVING count(name) > 1);
Update Active1 SET ID=(select MAX(ID) from Active1) where name= 'select NAME from Active1' where name= 'select NAME from Active1';
答案 0 :(得分:0)
这样做:
update Active1 t set t.ID =
(select MAX(a.ID) from Active1 a where a.name = 'vj')
where t.name = a.name ;